https://github.com/afsaredrisy/mrestclient
https://github.com/afsaredrisy/mrestclient
alamofire codable http-client mrest-client rest-api swift-restful
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/afsaredrisy/mrestclient
- Owner: afsaredrisy
- License: mit
- Created: 2020-02-07T18:47:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-22T12:07:02.000Z (over 6 years ago)
- Last Synced: 2025-08-16T16:46:05.074Z (11 months ago)
- Topics: alamofire, codable, http-client, mrest-client, rest-api, swift-restful
- Language: Swift
- Size: 172 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MRestClient
[](https://travis-ci.org/afsaredrisy/MRestClient)
[](https://cocoapods.org/pods/MRestClient)
[](https://cocoapods.org/pods/MRestClient)
[](https://cocoapods.org/pods/MRestClient)

## Example
MRestClient is the HTTP client implementation library written in swift, It is small , light weight & simple to use library for HTTP communication .The goal of this library is to reduce the effort to call REST-API with swift codable object. This is the generic implementation of swift object for request & response body so you can directly interact with codable object without worrying JSON conversion etc.
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
- [x] Xcode 11.
- [x] Swift 5.
- [x] iOS 11 or higher.
## Installation
MRestClient is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'MRestClient'
```
## Usage
HTTP methos **GET** , **POST**, **PUT** & **DELETE** are available to use, Following are the example of use case.
We will use following codable classes for request and response,
[These-Demo](http://dummy.restapiexample.com) APIs we are using for demonostration.
```swift
class Employee: Codable{
var profile_image: String
var employee_name: String
var employee_salary: String
var id: String
var employee_age: String
}
class Employees: Codable {
var data: [Employee]
var status: String
init(data: [Employee], status: String) {
self.data = data
self.status = status
}
}
```
**GET**
URL = http://dummy.restapiexample.com/api/v1/employees
Response JSON = Object of Empoyees
```swift
let base_url = "http://dummy.restapiexample.com"
let uri = "/api/v1/employees"
let rest_client = MRestClient(base_url: base_url)
rest_client.get(uri: uri, sucess: {(data, response) in
// Do stuff on Success data is object of Empoyees class
}, fail: {(error) in
// Fail callback
})
```
**POST**
Sample API description can found [here](http://dummy.restapiexample.com/create)
```swift
let uri = "/api/v1/create"
// First Generic is the type of object used in request body second used for Response body
let rest_Client = MRestClient(base_url: base_url)
rest_Client.post(url: uri, requestData: new_employee, sucess: {(data, response)in
// Do Stuff on sucess data is object of EmployeeWithStatus
}, fail: {(error) in
//Request has fail see error
})
```
For **PUT** & **DELETE** [See](https://github.com/afsaredrisy/MRestClient/tree/master/Example) demo application
## Contributions
If you want to improve the Demo or contribute in some way, please do so by creating a pull request. We welcome contributions.
## License
MRestClient is available under the MIT license. See the LICENSE file for more info.