Skip to main content

How to add routes

First we create a new folder called routes in the src directory. And make a new file hello-world.get

const { Route } = require('@sapphire/plugin-api');

class UserRoute extends Route {
run(_request, response) {
response.json({ message: 'Hello World' });
}
}
module.exports = {
UserRoute
};

A quick glance on what we did above:

  • First we extended the Route class to make our route
  • Second we defined the handler for the GET method defined in the filename
  • Finally, when GET /hello-world is called, the route will reply with the defined body