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:
泽熙 2016-10-03 18:27:49 +08:00 committed by GitHub
parent 57a0d198dc
commit 090d51aae5
1 changed files with 5 additions and 6 deletions

View File

@ -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)!"
}
```