An Generic HTTP Request Library For Swift

Related tags

Networking GRequest
Overview

GRequest

An HTTP request library written in Swift.

##Basic Usage Be simple, as it should be:

Request("https://api.github.com/repos/lingoer/SwiftyJSON/issues").get{
  response in
  println(response.content)//HTTP Body as NSData
}

If you need more infomation:

Request("https://api.github.com/repos/lingoer/SwiftyJSON/issues").get{
  response in
  println(response.headers)
  println(response.MIMEType)
  println(response.statusCode)
  println(response.encoding)
  println(response.error)
  println(response.content)//HTTP Body as NSData
  println(response.string)//HTTP Body as String
  println(response.object)//HTTP Body as Deserialized Custom Object, Default is NSData. See Below for more info
}

Use .query() to pass parameters for GET methods

Request("www.example.com/api").query(["labels":"discuss"]).get{
  response in
}

As for POST:

//This will encode body as application/x-www-form-urlencoded
Request("http://www.example.com").formBody(["key":"value"]).post{
  response in
}
//This will encode body as application/json
Request("http://www.example.com").jsonBody(["key":"value"]).post{
  response in
}
//You can custom your HTTP Body to POST, with Content-Type provided after it.
Request("http://www.example.com").body(customBodyData, typeString:"application/json; charset=utf-8").post{
  response in
}

More:

Request("http://www.example.com").head{
  response in
}
Request("http://www.example.com").put{
  response in
}
Request("http://www.example.com").delete{
  response in
}
Request("http://www.example.com").patch{
  response in
}

##Instances And Chainnings

A Request is in fact a GRequest<T>

It's typealias Request = GRequest<NSData> as default.

And a GRequest is a Generic class specifiying the behavior of the response.

Most methods returns an instance of the GRequest to make chains.

For example .path():

Request("https://api.github.com").path("/repos/lingoer/SwiftyJSON/issues").get{
  response in
}

###Response Deserialization As for the response behavior.

It's mostly about Response Deserialization:

Request("https://api.github.com/repos/lingoer/SwiftyJSON/issues").query(["labels":"discuss"]).get{
  (response:GResponse<JSONValue>) in
  println(response.object)//It's JSON Now
}

Note for more infomation about the JSONValue, see SwiftyJSON

If you need something.Just specify it!

Request("https://www.google.com/images/srpr/logo11w.png").get{
  (response:GResponse<UIImage>) in
  let image:UIImage = response.object!
}

If you don't want to do that every time:

let client = GRequest<JSONValue>("http://api.example.com")
client.path("/path/to/resource").get{
  response in
  println(response.object) //Its JSON Now
}

###Extensibility You can add your custom implementation of your Model deserialization.

By extentions conform protocol: ResponseDeserialization

extension CustomModel:ResponseDeserialization{
  class func convertFromData(data:NSData!) -> (CustomModel?, NSError?)
}

GRequest<CustomModel>("http://api.example.com").get{
  response in
  let model:CustomModel! = response.object
}
You might also like...
Generic Network Layer created using Swift.

Generic-Network-Layer_iOS Generic Network Layer created using URLSession. Networking is an essential element in app development, and you'll need API c

A lightweight generic networking API written purely in Swift

SwiftyNetworking SwiftyNetworking library is a generic networking library writte

Type-safe networking abstraction layer that associates request type with response type.

APIKit APIKit is a type-safe networking abstraction layer that associates request type with response type. // SearchRepositoriesRequest conforms to Re

Automatically sets the network activity indicator for any performed request.

BigBrother BIG BROTHER IS WATCHING YOU. BigBrother is a Swift library made for iOS that automatically watches for any performed request and sets the n

NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀
NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀

SONetworking NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. Project Folder and File Struc

YTKNetwork is a high level request util based on AFNetworking.

YTKNetwork What YTKNetwork is a high level request util based on AFNetworking. It's developed by the iOS Team of YuanTiKu. It provides a High Level AP

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

This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app.
This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app.

This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and Apple TV app. With this Framework you can create iPh

🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

Owner
Ruoyu Fu
Ruoyu Fu
Minimalistic Swift HTTP request agent for iOS and OS X

Agent Table of Contents Introduction Usage HTTP Verbs Overloading Method Chaining Response Closure Verbs Methods NSMutableURLRequest Contributing Lice

null 589 Jun 29, 2022
Http Request wrapper written in Swift

Net Net is a HttpRequest wrapper written in Swift Features GET, POST, PUT, DELETE method Powerful request params: nested params, number, string, dic,

Le Van Nghia 304 Jun 29, 2022
This package is meant to make http request of an easy way inspiren in the architecture of Moya package

NetworkAgent This package is meant to make http request of an easy way inspiren in the architecture of Moya package. This package is 100% free of depe

Angel Rada 19 Sep 8, 2022
iONess is HTTP Request Helper for iOS platform used by HCI iOS App

iONess iONess (iOS Network Session) is HTTP Request Helper for the iOS platform used by Home Credit Indonesia iOS App. It uses Ergo as a concurrent he

OSFE Homecredit Indonesia 1 Mar 28, 2022
Deal with query items, HTTP headers, request body and more in an easy, declarative way

Reusable system for complex URL requests with Swift. Deal with query items, HTTP headers, request body and more in an easy, declarative way. Check out our engineering blog to learn more!

Parable Health 19 Sep 5, 2022
Http - Demo for Http Layer

http Example To run the example project, clone the repo, and run pod install fro

null 0 Jan 24, 2022
AsyncHTTP - Generic networking library written using Swift async/await

Generic networking library written using Swift async/await

Laszlo Teveli 7 Aug 3, 2022
An iOS library to route API paths to objects on client side with request, mapping, routing and auth layers

WANetworkRouting Developed and Maintained by ipodishima Founder & CTO at Wasappli Inc. Sponsored by Wisembly A routing library to fetch objects from a

null 10 Nov 20, 2022
Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman)

RequestAdapter Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman) The code is taken from:

Mihaela Mihaljevic Jakic 0 Nov 22, 2021
A generic network layer written in swift

SwiftyNet 1.0.0 A generic network layer written in swift. you can use it as an abstraction layer above Alamofire with generic returned types. Installa

Mohamed Salah Zidane 17 Oct 11, 2021