https://github.com/satishbabariya/resty
Simple HTTP Networking Library with Async/Await and Codable.
https://github.com/satishbabariya/resty
async await cocoapods ios linux macos network networking requests responce resty swift swift-package-manager urlrequest urlsession
Last synced: about 1 month ago
JSON representation
Simple HTTP Networking Library with Async/Await and Codable.
- Host: GitHub
- URL: https://github.com/satishbabariya/resty
- Owner: satishbabariya
- License: mit
- Created: 2019-06-02T08:08:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-15T20:13:44.000Z (over 3 years ago)
- Last Synced: 2025-03-28T23:51:15.645Z (about 2 months ago)
- Topics: async, await, cocoapods, ios, linux, macos, network, networking, requests, responce, resty, swift, swift-package-manager, urlrequest, urlsession
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# resty
Simple HTTP Networking Library with Async/Await and Codable.```swift
let todos: [Todo] = try await FakeAPI.todos.request()
```[](https://developer.apple.com/swift)
[](http://cocoapods.org/pods/Resty)
[](http://cocoapods.org/pods/Resty)
[](http://cocoapods.org/pods/SwiftyContacts)
[](https://github.com/apple/swift-package-manager)- [Installation](#installation)
- [Get started](#get-started)
- [License](#license)## Installation
### CocoaPods
To integrate Resty into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'Resty'
```Then, run the following command:
```bash
$ pod install
```### Swift Package Manager
To use SwiftyContacts as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following in your Package.swift file.
``` swift
dependencies: [
.package(url: "https://github.com/satishbabariya/Resty.git", .upToNextMajor(from: "1.0.0"))
]
```## Get started
Import SwiftyContacts into your porject
```swift
import Resty
```### Request with codable async/await
```swift
let todos: [Todo] = try await FakeAPI.todos.request()
```### Request with codable
```swift
FakeAPI.todos.request(type: [Todo].self) { result in
switch result {
case let .success(todos):
// Array of [Todo]
case let .failure(error):
// error
}
}```
### REST API Setup
```swift
struct Todo: Codable {
let id: Int
let title: String
let completed: Bool
}enum FakeAPI: Resty {
case todos
}extension FakeAPI {
var host: String {
return "https://jsonplaceholder.typicode.com/"
}var path: String {
return ""
}var endpoint: String {
switch self {
case .todos:
return "todos"
}
}var method: HTTPMethod {
switch self {
case .todos:
return .get
}
}var parameters: [String: Any]? {
return nil
}var headers: [String: String]? {
return nil
}
}
```## Author
Satish Babariya, [email protected]
## License
Resty is available under the MIT license. See the LICENSE file for more info.