Improved Query Parameters section

This commit is contained in:
Eneko Alonso 2016-09-11 09:56:06 -07:00 committed by GitHub
parent cdfbd19e76
commit 361c6f5aa4
1 changed files with 7 additions and 3 deletions

View File

@ -36,7 +36,7 @@ let query = request.uri.query // query=hi
let fragment = request.uri.fragment // fragments-too
```
### Parameters
### Route Parameters
The url parameters associated with the request. For example, if we have a path registered as `hello/:name/age/:age`, we would be able to access those in our request, like so:
@ -56,6 +56,7 @@ These extract functions can cast to any `NodeInitializable` type, including your
> Note: Vapor also provides type safe routing in the routing section of our docs.
### Headers
These are the headers associated with the request. If you are preparing an outgoing request, this can be used to add your own keys.
@ -146,12 +147,15 @@ To access JSON directly on a given request, use the following:
let json = request.json["hello"]
```
## Query
## Query Parameters
The same applies to query convenience:
```swift
let query = request.query["hello"]
let query = request.query?["hello"] // String?
let name = request.query?["name"]?.string // String?
let age = request.query?["age"]?.int // Int?
let rating = request.query?["rating"]?.double // Double?
```
## Key Paths