From 361c6f5aa441ffec59f7213e3b18ecb3dd5bf758 Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Sun, 11 Sep 2016 09:56:06 -0700 Subject: [PATCH] Improved Query Parameters section --- http/request.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/http/request.md b/http/request.md index 65bf5a90..fdd3040b 100644 --- a/http/request.md +++ b/http/request.md @@ -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