Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonaskolb/NetworkRequest
Swift networking library for easily defining, executing, and mocking network requests
https://github.com/yonaskolb/NetworkRequest
networking rest swift
Last synced: 3 months ago
JSON representation
Swift networking library for easily defining, executing, and mocking network requests
- Host: GitHub
- URL: https://github.com/yonaskolb/NetworkRequest
- Owner: yonaskolb
- Created: 2019-08-13T04:59:16.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-02T23:26:29.000Z (about 3 years ago)
- Last Synced: 2024-07-22T03:01:51.578Z (3 months ago)
- Topics: networking, rest, swift
- Language: Swift
- Homepage:
- Size: 30.3 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NetworkRequest
A simple networking library for easily defining, executing and mocking network requests.
```swift
struct GetPosts: JSONDecodableRequest {
let userId: Inttypealias 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)
}
}
```