From c4d5b713faeeb93f87b014676033e52596a32af5 Mon Sep 17 00:00:00 2001 From: Sundeep Gupta Date: Wed, 14 Dec 2016 16:26:42 -0500 Subject: [PATCH] Explicitly unwrap optionals in JSON example Without this, compiler fails --- guide/json.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guide/json.md b/guide/json.md index 2579ede9..8b6d4fd9 100644 --- a/guide/json.md +++ b/guide/json.md @@ -27,11 +27,11 @@ To specifically target JSON, use the `request.json` property. ```swift drop.post("json") { request in - guard let name = request.json["name"].string else { - throw Abort.badRequest - } + guard let name = request.json?["name"]?.string else { + throw Abort.badRequest + } - return "Hello, \(name)!" + return "Hello, \(name)!" } ``` The above snippet will only work if the request is sent with JSON data.