Merge pull request #96 from sundeepgupta/fixJson

Explicitly unwrap optionals in JSON example
This commit is contained in:
Tanner 2016-12-15 10:29:45 -05:00 committed by GitHub
commit c38cc043cb
1 changed files with 4 additions and 4 deletions

View File

@ -27,11 +27,11 @@ To specifically target JSON, use the `request.json` property.
```swift
drop.post("json") { request in
guard let name = request.json["name"].string else {
throw Abort.badRequest
}
guard let name = request.json?["name"]?.string else {
throw Abort.badRequest
}
return "Hello, \(name)!"
return "Hello, \(name)!"
}
```
The above snippet will only work if the request is sent with JSON data.