Latest 0.4.3
License MIT
Platforms ios 8.0, tvos 9.0

Bridge Carthage compatibleCocoaPods Compatible

Simple Typed JSON HTTP Networking in Swift 4.0


GET<Dict>("").execute(success: { (response) in
    let ip: Dict = response

let postID = "1"
GET<Dict>("").execute(postID, success: { (response) in
    let post: Dict = response


let userComment = ["justin": "wow this is cool"]
let endpoint = POST<[String: AnyObject]>("")
endpoint.execute(params: userComment, success: { (commentResponse: [String: AnyObject]) -> () in
    // Handle success
}, failure: { (error, data, request, response) in
    // Handle failure


The power of Bridge is that it lets you create custom "Interceptors" to intercept process your requests before they are sent off to the internets, or to intercept and process your responses before they are returned to the caller’s success block.

Attach custom headers based on the endpoint, write retry handling, write authentication handlers, use method tunneling. Interceptors allow Bridge to be extremely extensible to your project needs.

*  Conform to the `ResponseInterceptor` protocol for any Bridge that
*  needs to work with or alter a request before it's sent over the wire
public protocol ResponseInterceptor {
    func process<ReturnType>(endpoint: Endpoint<ReturnType>, inout mutableRequest: NSMutableURLRequest)

*  Conform to the `ResponseInterceptor` protocol to work with data after
*  the request is returned with a response.
public protocol ResponseInterceptor {
    func process<ReturnType>(endpoint: Endpoint<ReturnType>, response: NSHTTPURLResponse?, responseObject: ResponseObject) -> ProcessResults


  • Retry (Retries requests on response if not 2xx code)
  • Model Cache (Caches objects on response)
  • [Method Tunneling]() (Changes the HTTP Verb)

Object Serialization

Bridge is implemented using generics which allow you to serialize to objects as long as your objects conform to the Parseable protocol.

public protocol Parseable {
    static func parseResponseObject(responseObject: AnyObject) throws -> AnyObject

It is left completely up to the developer on how you want to implement the Parseable protocol. You can manually create and serialize your objects:

class User: AnyObject, Parseable {
    var name: String?
    var email: String?
    var pictureURL: NSURL?

    static func parseResponseObject(responseObject: AnyObject) throws -> AnyObject {
        if let dict = responseObject as? Dictionary<String, AnyObject> {
            let user = User()
   = dict["name"] as? String
   = dict["email"] as? String
            user.pictureURL = NSURL(string: dict["avatar_url"] as! String)
            return user
        // If parsing encounters an error, throw enum that conforms to ErrorType.
        throw BridgeErrorType.Parsing

Or you can also serialize them using whatever serialization libraries you like. This gist is an example of out out-of-box working solution for Mantle if you’re already using Mantle models. No code change is required to your Mantle models.

Once models are setup, making calls are as simple as:

let endpoint = GET<GithubUser>("")
endpoint.execute(success: { (user: GithubUser) in

let endpoint = GET<Array<GithubUser>>("")
endpoint.execute(success: { (users: Array<GithubUser>) in
}, failure: { (error: NSError?) in

Advanced Features

Base URL

You can set the base url of your Bridge client

Bridge.sharedInstance.baseURL = ""
GET<GithubUser>("/users/rawrjustin") // expands to

Cancellation by Tag

Easily cancel any requests tagged with an identifier.


Variable endpoints

Similar to how Rails maps :id for resources, # is used as the character where a variable would be inserted into the path.

GET<Dict>("/photos/#") will map to /photos/1 if you pass in 1 in the first variadic parameter when you call execute(). You can have multiple variables, they will be mapped in order respectively.

Additional HTTP headers

Endpoint Specific Interceptors


  • iOS 8.0+
  • Swift 4.0



pod 'Bridge', '0.4.3'


github "rawrjustin/Bridge"


Bridge is licensed under MIT license.


Open an issue

Latest podspec

    "name": "Bridge",
    "version": "0.4.3",
    "summary": "Extremely Extensible Typed JSON HTTP Networking in Swift",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Justin Huang": "[email protected]"
    "social_media_url": "",
    "source": {
        "git": "",
        "tag": "0.4.3"
    "source_files": "Bridge/*",
    "swift_version": "4.0",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    "public_header_files": "Bridge/*.h"

Pin It on Pinterest

Share This