Routing in Vapor
Routing is a very important feature of any web application. It is the interface through which you can access the application and perform certain actions on it. HTTP is the protocol used in routing. We went through the basics of HTTP in Chapter 1, Getting Started with Server Swift, and as you might be aware, HTTP protocol requires a method, a path, a set of headers, and an optional body to make a request to the server. The server then responds back with a message that contains a status code, a set of Response headers, and a message body.
HTTP methods
For most of the web, there are five commonly used HTTP methods, which are as follows:
GET
POST
PATCH
PUT
DELETE
OPTIONS
There are also other methods that are less used and can be passed in the request to a web application. If it is able to handle it, the routing rules will determine who should be handling the request.
Vapor's droplets give us easy-to-use APIs to construct routes for these commonly used HTTP methods. All we need to do is...