Skip to content

Commit

Permalink
Merge pull request vapor#241 from martinpilch/enhance-vapor-controlle…
Browse files Browse the repository at this point in the history
…rs-documentation

Enhancing documentation for Vapor Controller
  • Loading branch information
Joannis authored Nov 27, 2017
2 parents b661dc0 + 9479f6b commit 5eec827
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 2.0/docs/vapor/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let hc = HelloController()
drop.get("hello", handler: hc.sayHello)
```

Since the signature of our `sayHello` method matches the signature of the closure for the `drop.get` method, we can pass it directly.
Since the signature of our `sayHello` method matches the signature of the closure for the `drop.get` method, we can pass it directly. If you want to test it locally simply open [http://localhost:8080/hello?name=John](http://localhost:8080/hello?name=John).

### Type Safe

Expand All @@ -45,7 +45,7 @@ You can also use controller methods with type-safe routing.
final class HelloController {
...

func sayHelloAlternate(_ req: Request) -> ResponseRepresentable {
func sayHelloAlternate(_ req: Request) throws -> ResponseRepresentable {
let name: String = try req.parameters.next(String.self)
return "Hello, \(name)"
}
Expand All @@ -59,7 +59,7 @@ let hc = HelloController()
drop.get("hello", String.parameter, handler: hc.sayHelloAlternate)
```

Since `drop.get` accepts a signature `(Request) throws -> ResponseRepresentable`, our method can now be used as the closure for this route.
Since `drop.get` accepts a signature `(Request) throws -> ResponseRepresentable`, our method can now be used as the closure for this route. In this case to test it locally open [http://localhost:8080/hello/John](http://localhost:8080/hello/John).

!!! note
Read more about type safe routing in the [Routing Parameters](https://docs.vapor.codes/2.0/routing/parameters/#type-safe) section.
Expand Down

0 comments on commit 5eec827

Please sign in to comment.