From 619d6659bc399a8b6088eb09153007ae79db8a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= <3lvis@users.noreply.github.com> Date: Sun, 29 May 2016 09:40:18 +0200 Subject: [PATCH] Add ID-based cancellation to README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 17cb59a..7813ee8 100755 --- a/README.md +++ b/README.md @@ -229,6 +229,8 @@ networking.POST("/upload", parameterType: .Custom("application/octet-stream"), p ## Cancelling a request +### Using path + Cancelling any request for a specific path is really simple. Beware that cancelling a request will cause the request to return with an error with status code -999. ```swift @@ -240,6 +242,27 @@ networking.GET("/get") { JSON, error in networking.cancelGET("/get") ``` +### Using request identifier + +Using `cancelPOST("/upload")` would cancel all POST request for the specific path, but in some cases this isn't what we want. For example if you're trying to upload two photos, but the user requests to cancel one of the uploads, using `cancelPOST("/upload") would cancell all the uploads, this is when ID based cancellation is useful. + +```swift +let networking = Networking(baseURL: "http://httpbin.org") + +// Start first upload +let firstRequestID = networking.POST("/upload", parts: ...) { JSON, error in + //... +} + +// Start second upload +let secondRequestID = networking.POST("/upload", parts: ...) { JSON, error in + //... +} + +// Cancel only the first upload +networking.cancel(firstRequestID) +``` + ## Faking a request Faking a request means that after calling this method on a specific path, any call to this resource, will return what you registered as a response. This technique is also known as mocking or stubbing.