Explicitly unwrap optionals in JSON example

Without this, compiler fails
This commit is contained in:
Sundeep Gupta 2016-12-14 16:26:42 -05:00
parent 58177d9c13
commit c4d5b713fa
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.