mirror of https://github.com/vapor/docs.git
Program syntax error
drop.any("hello") { request in
guard let name = request.data["name"].string else {
throw Abort.badRequest
}
return "Hello, \(name)!"
}
---------------------------------------------------------------
drop.get("hello") { request in
guard let name = request.data["name"]?.string else {
throw Abort.badRequest
}
return "Hello, \(name)!"
}
This commit is contained in:
parent
57a0d198dc
commit
090d51aae5
|
|
@ -11,12 +11,11 @@ JSON is an integral part of Vapor. It powers Vapor's [Config](config.md) and is
|
|||
JSON is automatically available in `request.data` alongside form-urlencoded data and query data. This allows you to focus on making a great API, not worrying about what content types data will be sent in.
|
||||
|
||||
```swift
|
||||
drop.any("hello") { request in
|
||||
guard let name = request.data["name"].string else {
|
||||
throw Abort.badRequest
|
||||
}
|
||||
|
||||
return "Hello, \(name)!"
|
||||
drop.get("hello") { request in
|
||||
guard let name = request.data["name"]?.string else {
|
||||
throw Abort.badRequest
|
||||
}
|
||||
return "Hello, \(name)!"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue