Moya 문서

[한글 번역] Moya Readme.md - Usage (2)

초가을우엉차 2022. 6. 8. 01:07

Usage

 ▶  사용법

 

 

1. After some setup, using Moya is really simple. You can access an API like this:

 ▶  몇 가지 설정이 끝나면, Moya를 사용하는 것은 정말 간단합니다. 다음과 같이 API에 액세스 할 수 있습니다.

provider = MoyaProvider<GitHub>()
provider.request(.zen) { result in
    switch result {
    case let .success(moyaResponse):
        let data = moyaResponse.data
        let statusCode = moyaResponse.statusCode
        // do something with the response data or statusCode
        // 응답 데이터 또는 statusCode로 작업 수행
        
    case let .failure(error):
        // this means there was a network failure - either the request
        // wasn't sent (connectivity), or no response was received (server
        // timed out).  If the server responds with a 4xx or 5xx error, that
        // will be sent as a ".success"-ful response.
        
        // 이것은 네트워크 오류가 있음을 의미합니다.
        // 전송되지 않았거나(연결성) 응답이 수신되지 않았습니다(서버
        // 시간 초과).서버가 4xx 또는 5xx 오류로 응답하는 경우
        // ".success"-ful 응답으로 전송됩니다.
    }
}

 

 

2. That's a basic example. Many API requests need parameters.

 ▶  기본적인 예입니다. 많은 API 요청에는 매개변수가 필요합니다. 

 

3. Moya encodes these into the enum you use to access the endpoint, like this:

 ▶  Moya는 이를 다음과 같이 엔드포인트에 액세스 하는 데 사용하는 거형으로 인코딩합니다.

provider = MoyaProvider<GitHub>()
provider.request(.userProfile("ashfurrow")) { result in
    // do something with the result
    // 응답값으로 뭔가를 실행
}
 
 

4. No more typos in URLs. No more missing parameter values. No more messing with parameter encoding.

 ▶  URL에 더 이상 오타가 없습니다. 더 이상 누락된 매개변수는 없습니다. 더 이상 매개변수 인코딩을 어지럽힐 필요가 없습니다.

 

 

5. For more examples, see the documentation.

 ▶  더 많은 예시는 문서를 참조하세요.

 


출처

 

GitHub - Moya/Moya: Network abstraction layer written in Swift.

Network abstraction layer written in Swift. Contribute to Moya/Moya development by creating an account on GitHub.

github.com