Skip to content

Commit

Permalink
Add ID-based cancellation to README
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed May 29, 2016
1 parent 180889f commit 619d665
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 619d665

Please sign in to comment.