Routing

Routing essentially means how URLs are mapped to actions and variables.

When a URL is accessed on your domain, a request is sent to the router that is available in “app.js” file or a plugin. This router is responsible for finding a matching page and, accordingly, routing the request to the page. contentstack-express allows you to define these routing rules.

Example:

Let’s define a rule where the router will return “hello world” when a GET request is made to the home page.

// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
  res.send('hello world');
});

Similarly, you can variously define custom routes. contentstack-express supports all the route methods, paths, and handlers that are provided by Node.js Express.

More articles in "Advanced Topics"

On This Page

top-arrow