mirror of https://github.com/vapor/docs.git
750 B
750 B
Synchronous routing
The SyncRouter protocol can be applied on top of any router without additional implementation.
let router: SyncRouter = ...
Registering a route
The on function on a SyncRouter registers a route to the provided path. The following registers a GET /hello/world route.
It responds with "Hello world!"
router.on(.get, to: "hello", "world") { request in
return "Hello world!"
}
The .get represents the Method you want to use. to: "hello", "world" registers the path /hello/world.
The trailing closure receives a Request. The route can throw errors and needs to return a ResponseRepresentable conforming type.