Request data

Every route call gets passed a request object that can be used to grab query and path parameters.

The following example shows how to access JSON, Query, and form-encoded data from the request:

drop.post("hello") { request in 
guard let name = request.data["name"]?.string else {
return "Please include a name"
}

return "Hello, (name)!"
}

In this example, we read the request data and return a string.

Vapor also provides the means for session management, database connection, and view responses with HTML or Stencil template-included HTML pages. There is an example Vapor project (https://github.com/qutheory/vapor-example) that can be used and modified for our purposes. We are not going to explore Vapor in depth since it is still a work-in-progress and the Vapor documentation (https://vapor.github.io/documentation) already provides information required to get familiar with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset