A light weight network library with automated model parser for rapid development

Related tags

Networking Gem
Overview

Gem

A light weight network library with automated model parser for rapid development.

Swift 4.1 Platforms iOS Xcode 9.2 Gemnasium Ratting license

Managing all http request with automated model parser calls in app with closure

Requirements

  • iOS 10.0+
  • Swift 4.1+
  • Xcode 9.2+

Installation

CocoaPods

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

use_frameworks!

pod "Gem"

or

use_frameworks!

pod 'Gem', git: 'https://github.com/Albinzr/Gem', :tag => '1.0.3'

Carthage

To integrate Task into your Xcode project using Carthage, specify it in your Cartfile:

github "Albinzr/Gem"

Usage & Requirement

  1. All model class should have Codable protocol
  2. Naming for variable should be as follow
           
           //json
           {
               name:"Albin CR",
               published_on:123455,
               Time:"23.10"
               
            }
           // model class
           class Details:Codable{
               var name:String? // same variable as in json
               var publishedOn:Int? // incase of snake casing use camel casing of the same name
               var Time:String // same variable as in json
           }

Example

Get Request

//model

class User:Codable{
    
    var id:Int?
    var name:String?
    var username:String?
    var email:String?
    var address:Address?
    var phone:String?
    var website:String?
    var company:Company?
    
}

Gem.request(url: "https://jsonplaceholder.typicode.com/uses", method: Methods.get, model:User.self, 
    Success: { (data, response) in        
                 // success block
                print(data,response)
      
        }) { (error, response) in
              //error block
              print(error,response)
            
        }

response - contain all details related to network call like status code etc..

Post Request

class User:Codable{
    
    var id:Int?
    var name:String?
    var username:String?
    var email:String?
    var address:Address?
    var phone:String?
    var website:String?
    var company:Company?
    
}

let param: [String : Any] = [
            "id":12324,
            "name":"Albin CR",
            "username":"Albi",
            "email":"[email protected]",
            "phone":"8907575123",
            "website":"www.albin.in",
            "company":[
                "name":"Quin",
                "catchPhrase":"Time to change",
                "bs":"Pika",
            ]
        ]
        Gem.request(url: "https://jsonplaceholder.typicode.com/posts", method: Methods.post,parameter:param,header:nil, model:User.self, Success: { (data, response) in
            
            print(data,response ?? "")
            print("success")
            
        }) { (error, response) in
            
            print(error ?? "",response!.statusCode)
            
        }
        

ImageUpload

class ImageUpload:Codable{
    
    var link:String?
    var width:Float?
    var height:Float?
    var id:String?
    
}

let image:UIImage = UIImage(named: "scan") // or image url 
        let imageData:Data = UIImagePNGRepresentation(image)!
        let base64Data =  imageData.base64EncodedString()
        
        let param:[String:Any] = [
            "image":base64Data
        ]
        
        let header:[String:String] = [
            "Authorization":"Client-ID {{your client key}}",//replace your client key
            "Content-type":"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'"
        ]
        
        Gem.request(url: "https://api.imgur.com/3/image", method: Methods.post,parameter:param,header:header,    model:ImageUpload.self, Success: { (data, response) in
            
            print(data,response ?? "")
            print("success")
            
        }) { (error, response) in
            
            print(error ?? "",response!.statusCode)
            
        }

PR/request/suggestions are always welcome

You might also like...
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
A lightweight, one line setup, iOS / OSX network debugging library! 🦊

Netfox provides a quick look on all executed network requests performed by your iOS or OSX app. It grabs all requests - of course yours, requests from

An iOS LAN  Network Scanner library
An iOS LAN Network Scanner library

MMLanScan MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices and their MAC Address, hostname

A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.

XMNetworking English Document XMNetworking 是一个轻量的、简单易用但功能强大的网络库,基于 AFNetworking 3.0+ 封装。 其中,XM 前缀是我们团队 Xcode-Men 的缩写。 简介 如上图所示,XMNetworking 采用中心化的设计思想

A new, clean and lean network interface reachability library written in Swift.

Reachability A new, clean and lean network interface reachability library written in Swift. Remarks Network reachability changes can be monitored usin

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)

SwiftSoup is a pure Swift library, cross-platform (macOS, iOS, tvOS, watchOS and Linux!), for working with real-world HTML. It provides a very conveni

Kanna(鉋) is an XML/HTML parser for Swift.

Kanna(鉋) Kanna(鉋) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!). It was inspired by Nokogiri(鋸). ℹ️ Documentation Fea

Ji (戟) is an XML/HTML parser for Swift
Ji (戟) is an XML/HTML parser for Swift

Ji 戟 Ji (戟) is a Swift wrapper on libxml2 for parsing XML/HTML. Features Build XML/HTML Tree and Navigate. XPath Query Supported. Comprehensive Unit T

Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Swift guarded model initializers for SwiftyJSON

GuardedSwiftyJSON Why should I use this? This library makes initializing models with JSON data with SwiftyJSON a lot easier. Often with SwiftyJSON I e

Comments
  • Headers are sent in reversed order

    Headers are sent in reversed order

    I'm using the 1.0.3 version of the library.

    Let's see the part of ImageUpload example from README.md.

    let header:[String:String] = ["Authorization":"Client-ID"]

    In this case the header key is "Authorization" and the value is "Client-ID". When the request is sent, the server gets this header in reversed order, so the key is "Client-ID" and the value is "Authorization".

    In short: value: key instead of key:value

    Fix: Gem/Gem.swift:110 Should be: request.addValue(headerDetail.value, forHTTPHeaderField: headerDetail.key)

    P.s.: Please specify CONTRIBUTING.md file to clarify the process of contribution.

    opened by madamm91 1
Owner
Albin CR
Albin CR
NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

null 4 Dec 2, 2022
DBNetworkStack is a network abstraction for fetching request and mapping them to model objects

DBNetworkStack Main Features ?? Typed network resources ?? Value oriented architecture ?? Exchangeable implementations ?? Extendable API ?? Composable

DB Systel GmbH 33 Jan 10, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
A network extension app to block a user input URI. Meant as a network extension filter proof of concept.

URIBlockNE A network extension app to block a user input URI. Meant as a network extension filter proof of concept. This is just a research effort to

Charles Edge 5 Oct 17, 2022
Say goodbye to the Fat ugly singleton Network Manager with this Network Layer

MHNetwork Protocol Oriented Network Layer Aim to avoid having bloated singleton NetworkManager Philosophy the main philosophy behind MHNetwork is to h

Mohamed Emad Hegab 19 Nov 19, 2022
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Jan 6, 2023
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
Impervious is a privacy and security-focused browser with native DANE support and a decentralized p2p light client.

Impervious iOS The first browser with support for native DNS-Based Authentication of Named Entities (DANE) with true downgrade protection, and the fir

Impervious Inc 25 Jun 15, 2022
Beacon is a privacy and security-focused browser with native DANE support and a decentralized p2p light client.

Beacon iOS The first browser with support for native DNS-Based Authentication of Named Entities (DANE) with true downgrade protection, and the first b

Impervious Inc 25 Jun 15, 2022