iOS / OS X networking library written in Swift. Main purpose of this library is to be used as a API client layer in your app.
- Object oriented architecture
- Written in Swift
- Targeted for both iOS and OS X platforms
- Supports HTTP protocol methods: GET, PUT, POST, DELETE, PATCH
- Supports setting custom HTTP headers
- Supports request parameters encoded as Query String, URL Form or JSON Body
- Response validators (ex. data persistance and length, status code)
- Response deserializers (ex. JSON deserializer, image deserializer)
NSURLSession
connections withURLSessionProvider
- Supports custom caching with
URLCacheProvider
that gives full control of cache and allows to use your app in offline mode - Extensible architecture allows to implement custom validators, deserializers etc.
-
Request
Describes a request with given method, url, headers and parameters
-
Response
Describes response for given
Request
-
Task
Represents a task that returns
Response
for aRequest
usigng givenProvider
-
Provider
Can perform a
Task
and returnResponse
for givenRequest
-
RequestHeaders
Configures
Request
with given header fields-
RequestStandardHeaders
You can use this class to provide additional headers for your requests
-
-
RequestParameters
Configures
Request
with given parameters-
RequestQueryStringParameters
Set as URL Query String parameters
-
RequestFormURLEncodedParameters
Encoded as HTTP URL Form
-
RequestJSONParameters
Encoded as JSON and submitted in request body. Shouldn't be used with
GET
requests. -
RequestMultipartFormDataParameters
Encoded as HTTP Multipart Form Data and submitted in request body. You can set string and file type parameters. Use this class when you want to implement file upload in your app.
-
-
ResponseValidator
Validates
Response
and generates errors if it doesn't pass validation.-
ResponseDataValidator
Checks if
Response
constains valid data with correct length -
ResponseStatusCodeValidator
Checks if
Response
has status code in given range
-
-
ResponseDeserializer
Deserializes
Response
data-
ResponseJSONDeserializer
to JSON dictionary
-
ResponseImageDeserializer
to
UIImage
orNSImage
, depending on platform
-
-
Operation
Performs
Task
and allows to handle errors or success easily, can be chained to implement custom caching policy
You can add DRNet library to your project as a git submodule, or just copy it manualy. The library was prepared to be used as a embedded framework in your app. Refer to example app project for hints.
You can also integrate DRNet with your project using Cocoapods (version >= 0.36) by adding the line below to your Podfile:
pod 'DRNet', :git => 'https://github.com/darrarski/DRNet.git'
For more informations refer to Cocoapods documentation.
Check out included examples:
- iOS: Loading JSON using GET request with query string parameters
- iOS: UIImageView extension with remote image loader that supports caching and offline mode
The MIT License (MIT) - check out included LICENSE file
DRNet library takes some ideas from Alamofire by Mattt Thompson with more object oriented architecure and easy extensibility.
The library uses code from CryptoSwift by Marcin Krzyzanowski to compute MD5 hashes for cached network requests.