Logotype Sitevision Developer
Log in
Log in

router

Routing

Routes handle how a RESTApp responds to requests. The router object provides methods to respond to the following request methods:

  • GET
  • PUT
  • POST
  • DELETE
  • PATCH (@since 2023.02.1)

A route definition has the following structure:

Basic examples:

Middleware

A middleware function is a function that have access to the request object (req), response object (res) and a function (next) triggering the next function in the request-response chain. The next function will either be another middleware or the actual route function. Middleware functions are executed every time the app receives a request matching a route.

Middleware functions are registered using the router.use-method:

Requests may be terminated and altered within a middleware. Keep in mind that the next()-function must be called in order to pass over control to the next function in the stack.

Multiple middleware functions may be registered and they will be executed in the order they are registered, i.e. top-down.

Route parameters

Route parameters are used to capture a value in the URL. Below is an example of a path that will capture id on the /user route.

Did you find the content on this page useful?