Giter Club home page Giter Club logo

mrestclient's Introduction

MRestClient

CI Status Version License Platform

image

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

  • Xcode 11.
  • Swift 5.
  • iOS 11 or higher.

Installation

MRestClient is available through CocoaPods. To install it, simply add the following line to your Podfile:

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 APIs we are using for demonostration.

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

        let base_url = "http://dummy.restapiexample.com"
        let  uri = "/api/v1/employees"
        let rest_client = MRestClient<None, Employees>(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

      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<EmpDTO, EmployeeWithStatus>(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 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.

mrestclient's People

Contributors

afsaredrisy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.