diff --git a/couscous.yml b/couscous.yml index 20b2ade2..e9123674 100644 --- a/couscous.yml +++ b/couscous.yml @@ -4,7 +4,7 @@ template: title: Vapor Documentation subTitle: A web framework and server for Swift that works on macOS and Ubuntu. -baseUrl: https://qutheory.github.io/documentation +baseUrl: https://vapor.github.io/documentation menu: sections: diff --git a/guide/json.md b/guide/json.md index e96edf45..d6ee83b4 100644 --- a/guide/json.md +++ b/guide/json.md @@ -26,7 +26,7 @@ This will return a greeting for any HTTP method or content type that the `name` 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 @@ -44,8 +44,8 @@ To respond with JSON, simply wrap your data structure with `JSON(node: )` ```swift drop.get("version") { request in return try JSON(node: [ - "version": "1.0 - "]) + "version": "1.0" + ]) } ``` diff --git a/routing/basic.md b/routing/basic.md index afa404ba..55ee2be3 100644 --- a/routing/basic.md +++ b/routing/basic.md @@ -46,7 +46,7 @@ An alternate syntax that accepts a `Method` as the first parameter is also avail ```swift drop.add(.trace, "welcome") { request in - return "Hello" + return "Hello" } ``` @@ -70,7 +70,7 @@ A custom [Response](../http/response.md) can be returned. ```swift drop.get("vapor") { request in - return Response(redirect: "http://vapor.codes") + return Response(redirect: "http://vapor.codes") } ``` @@ -88,7 +88,7 @@ A lot of types in Vapor conform to this protocol by default: ```swift drop.get("json") { request in - return try JSON(node: [ + return try JSON(node: [ "number": 123, "text": "unicorns", "bool": false @@ -104,7 +104,7 @@ If you are unable to return a response, you may `throw` any object that conforms ```swift drop.get("404") { request in - throw Abort.notFound + throw Abort.notFound } ``` @@ -112,7 +112,7 @@ You can customize the message of these errors by using `Abort` ```swift drop.get("error") { request in - throw Abort.custom(status: .badRequest, message: "Sorry 😱") + throw Abort.custom(status: .badRequest, message: "Sorry 😱") } ``` @@ -120,9 +120,27 @@ These errors are caught by default in the `AbortMiddleware` where they are turne ```json { - error: true, - message: "" + error: true, + message: "" } ``` If you want to override this behavior, remove the `AbortMiddleware` from the `Droplet`'s middleware and add your own. + +## Fallback + +Fallback routes allow you to match multiple layers of nesting slashes. + +```swift +app.get("anything", "*") { request in + return "Matches anything after /anything" +} +``` + +For example, the above route matches all of the following and more: + +- /anything +- /anything/foo +- /anything/foo/bar +- /anything/foo/bar/baz +- ... diff --git a/routing/parameters.md b/routing/parameters.md index 08121b6a..7669657b 100644 --- a/routing/parameters.md +++ b/routing/parameters.md @@ -119,3 +119,14 @@ drop.get("v1", "users", ":userId", "posts", ":postId", "comments": ":commentId") ``` Request parameters can be accessed either as a dictionary or using the `extract` syntax which throws instead of returning an optional. + +### Groups + +Manual request parameters also work with [groups](group.md). + +```swift +let userGroup = drop.grouped("users", ":userId") +userGroup.get("messages") { req in + let user = try req.parameters.extract("userId") as User +} +``` \ No newline at end of file