![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
github.com/bridgenetworking/bridge
Simple Typed JSON HTTP Networking in Swift 4.0
GET<Dict>("http://httpbin.org/ip").execute(success: { (response) in
let ip: Dict = response
})
let postID = "1"
GET<Dict>("http://jsonplaceholder.typicode.com/posts/#").execute(postID, success: { (response) in
let post: Dict = response
})
let userComment = ["justin": "wow this is cool"]
let endpoint = POST<[String: AnyObject]>("https://api.bridge.com/comments")
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
}
Examples:
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()
user.name = dict["name"] as? String
user.email = 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>("https://api.github.com/users/rawrjustin")
endpoint.execute(success: { (user: GithubUser) in
print(user)
})
let endpoint = GET<Array<GithubUser>>("https://api.github.com/users")
endpoint.execute(success: { (users: Array<GithubUser>) in
print(users)
}, failure: { (error: NSError?) in
print(error)
})
You can set the base url of your Bridge client
Bridge.sharedInstance.baseURL = "http://api.github.com"
GET<GithubUser>("/users/rawrjustin") // expands to http://api.github.com/users/rawrjustin
Easily cancel any requests tagged with an identifier.
Bridge.sharedInstance.cancelWithTag("DebouncedSearch")
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.
pod 'Bridge', '0.4.3'
github "rawrjustin/Bridge"
Bridge is licensed under MIT license.
Open an issue
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.