目录
目录README.md

NetworkRequest

A simple networking library for easily defining, executing and mocking network requests.


struct GetPosts: JSONDecodableRequest {  
    let userId: Int

    typealias ResponseType = [Post]
    let path: String = "/posts"
    var urlParams: [String: Any?] { return ["userId": userId] }
}

struct Post: Decodable {
    let userId: Int
    let id: Int
    let title: String
    let body: String
}

let networkService = HTTPNetworkService(baseURL: "https://jsonplaceholder.typicode.com")
let request = GetPosts(userId: 2)

networkService.makeRequest(request) { result in
    switch result {
    case .success(let posts): // posts is [Post]
        print(posts) 
    case .failure(let error): // error is RequestError
        print(error)
    }
}
关于
70.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号