Latest 0.1.1
Homepage https://github.com/arcadekenan/HTTPLayer
License MIT
Platforms ios 10.0
Authors

Straight to the Point HTTP Networking for JSON Services in Swift

Platform

Features

  • [x] Easy to use and read Request / Response Methods
  • [x] JSON Responses
  • [x] Setting Hosts, Contexts and Headers only once and use it by a Key defined by you
  • [x] GET Methods with Query and Path Parameters
  • [x] POST Method with JSON Body
  • [x] PUT Methods with JSON Body and/or Query and Path Parameters
  • [x] DELETE Methods with JSON Body and/or Query and Path Parameters
  • [X] Unit and Integration Test Coverage – (Need more test Coverage)
  • [X] HTTP Response Validation
  • [X] Custom Error Response Object
  • [ ] OPTION and PATCH methods
  • [ ] TLS Certificate and Public Key Pinning

Requirements

  • iOS 10.0+
  • Xcode 10.2+
  • Swift 5+

Installation

CocoaPods

CocoaPods is a dependency manager for projects. For its documentation on Usage and Installation, visit this site.

On your Podfile add:

pod 'HTTPLayer'

On your Terminal, navigate to your project folder and run this command:

$ pod install

Usage

Configuration

To use HTTPLayer you just need to add its import on any class you might want.

import HTTPLayer

It is recommended to configure all your hosts, contexts and headers on the AppDelegate file, like the example bellow:

  • Inside the " func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {} " add configuration like:
    
    //For adding Hosts and Context or Headers
    HTTP.Config.add

//For setting multiplus Hosts and Context or Headers at once
HTTP.Config.set

//For changing already added Headers
HTTP.Config.change

//For removing any Header that has already been added
HTTP.Config.remove


These are the already implemented methods that you can choose from. All of them are accessable through "HTTP.Request" and all of them are documented and avaliable on the Xcode Autocomplete Shortcut. (E and D stands for Generic Object that conforms to Encodable for E and Decodable for D)

-  GET - (Add the parameter "receivingAsError: T.self" to use a custom Error Response Object)
```swift
//Without Parameters:
HTTP.Request.get(from: String, withHostAndContext: String, andHeaders: String, receivingObjectType: D.self, completion: (Result<D, Error>) -> ()) 

//Path Parameters:
HTTP.Request.get(from: String, usingPathParameters: [String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())

//Query Parameters:
HTTP.Request.get(from: String, usingQueryParameters: [String : String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())
  • POST – (Add the parameter "receivingAsError: T.self" to use a custom Error Response Object)

    HTTP.Request.post(to: String, withBody: Encodable, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())
  • PUT – (Add the parameter "receivingAsError: T.self" to use a custom Error Response Object)
    
    //Path Parameters:
    HTTP.Request.put(on: String, withBody: E, andPathParameters: [String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())

//Query Parameters:
HTTP.Request.put(on: String, withBody: E, andQueryParameters: [String : String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())


- DELETE - (Add the parameter "receivingAsError: T.self" to use a custom Error Response Object)
```swift
//Path Parameters
HTTP.Request.delete(from: String, withPathParameters: [String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())

//Query Parameters
HTTP.Request.delete(from: String, withQueryParameters: [String : String]?, fromHostAndContext: String, andHeaders: String?, receivingObjectType: D.self, completion: (Result<D, Error>) -> ())

Credits

https://github.com/arcadekenan

Disclosure

In case you believe you have found any issues and or vulnerability, feel free to reach to [email protected] or even submit a pull request.

License

HTTPLayer is released under the MIT license.

Latest podspec

{
    "name": "HTTPLayer",
    "version": "0.1.1",
    "summary": "Straight to the Point HTTP Networking for JSON Services in Swift",
    "swift_versions": "5.0",
    "description": "A framework intending to abstract URLSessions and HTTP Requests to help avoid repeting code and lenghty methods.nIt is a framework intended for Swift 5 only and implemented using generics so its possible to receive any type of response as long as it conforms to Codable.nAll responses once successfully parsed are wrapped on the Swift's 5 Result object.",
    "homepage": "https://github.com/arcadekenan/HTTPLayer",
    "license": "MIT",
    "authors": {
        "Davi Bispo": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/arcadekenan/HTTPLayer.git",
        "tag": "0.1.1"
    },
    "source_files": [
        "HTTPLayer",
        "HTTPLayer/**/*.swift"
    ],
    "exclude_files": "Classes/Exclude"
}

Pin It on Pinterest

Share This