From f63a6aad73efee58c4bec288f20e52a89f09fb63 Mon Sep 17 00:00:00 2001 From: vikin <986465329@qq.com> Date: Sat, 17 Sep 2016 11:31:13 +0800 Subject: [PATCH 1/2] update get Content command If you want to get content , must be unpacking; ```swift request.data["hello"].string -> request.data["hello"]!.string ``` --- http/request.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http/request.md b/http/request.md index fdd3040b..de71927d 100644 --- a/http/request.md +++ b/http/request.md @@ -118,7 +118,7 @@ Generally when we're sending or receiving requests, we're using them as a way to For example, say I receive a request to `http://vapor.codes?hello=world`. ```swift -let world = request.data["hello"].string +let world = request.data["hello"]!.string ``` This same code will work if I receive a JSON request, for example: @@ -132,7 +132,7 @@ This same code will work if I receive a JSON request, for example: Will still be accessible through data. ```swift -let world = request.data["hello"].string +let world = request.data["hello"]!.string ``` This also applies to multi-part requests and can even be extended to new types such as XML or YAML through middleware. From d4233072825ac3a41649f907bd929c0dd4992be9 Mon Sep 17 00:00:00 2001 From: vikin <986465329@qq.com> Date: Sat, 17 Sep 2016 13:09:46 +0800 Subject: [PATCH 2/2] Update request.md --- http/request.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/http/request.md b/http/request.md index de71927d..05718ff9 100644 --- a/http/request.md +++ b/http/request.md @@ -118,7 +118,7 @@ Generally when we're sending or receiving requests, we're using them as a way to For example, say I receive a request to `http://vapor.codes?hello=world`. ```swift -let world = request.data["hello"]!.string +let world = request.data["hello"]?.string ``` This same code will work if I receive a JSON request, for example: @@ -132,8 +132,9 @@ This same code will work if I receive a JSON request, for example: Will still be accessible through data. ```swift -let world = request.data["hello"]!.string +let world = request.data["hello"]?.string ``` +> Note: Force unwrap should never be used. This also applies to multi-part requests and can even be extended to new types such as XML or YAML through middleware.