Merge pull request #109 from vapor/Casperhr-form-data-ex

Updated with a form-data example
This commit is contained in:
Casper Rasmussen 2017-01-13 19:52:39 +01:00 committed by GitHub
commit 2417d36d87
1 changed files with 10 additions and 0 deletions

View File

@ -30,11 +30,21 @@ try drop.client.get("https://api.spotify.com/v1/search", query: ["type": "artist
In addition to `GET` requests, Vapor's client provides support for most common HTTP functions. `GET`, `POST`, `PUT`, `PATCH`, `DELETE`
### POST as json
```swift
let bytes = myJSON.makeBytes()
try drop.client.post("http://some-endpoint/json", headers: ["Auth": "Token my-auth-token"], body: .data(jsonBytes))
```
### POST as x-www-form-urlencoded
```swift
try drop.client.post("http://some-endpoint", headers: [
"Content-Type": "application/x-www-form-urlencoded"
], body: Body.data( Node([
"email": "mymail@vapor.codes"
]).formURLEncoded()))
```
### Full Request
To access additional functionality or custom methods, use the underlying `request` function directly.