mirror of https://github.com/vapor/docs.git
Explicitly unwrap optionals in JSON example
Without this, compiler fails
This commit is contained in:
parent
58177d9c13
commit
c4d5b713fa
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue