Routing

Learn how to use the routing system in Aurora

Routing

Basic Routing

Aurora uses "get", "post", "put", "patch", "delete" methods to register routes.

Get

The get method is used to register a route that will only respond to HTTP GET requests:

Aurora.get('/', function(req, res)
    res.send("Hello World")
end)
function get(path: string, handler: (request: Request, resonse: RouteResponse) -> RouteResponse, middleware: { string }?)

Post

The post method is used to register a route that will only respond to HTTP POST requests:

Aurora.post('/', function(req, res)
    res.send("Hello World")
end)
function post(path: string, handler: (request: Request, resonse: RouteResponse) -> RouteResponse, middleware: { string }?)

Put

The put method is used to register a route that will only respond to HTTP PUT requests:

Aurora.put('/', function(req, res)
    res.send("Hello World")
end)
function put(path: string, handler: (request: Request, resonse: RouteResponse) -> RouteResponse, middleware: { string }?)

Patch

The patch method is used to register a route that will only respond to HTTP PATCH requests:

Aurora.patch('/', function(req, res)
    res.send("Hello World")
end)
function patch(path: string, handler: (request: Request, resonse: RouteResponse) -> RouteResponse, middleware: { string }?)

Delete

The delete method is used to register a route that will only respond to HTTP DELETE requests:

Aurora.delete('/', function(req, res)
    res.send("Hello World")
end)
function delete(path: string, handler: (request: Request, resonse: RouteResponse) -> RouteResponse, middleware: { string }?)

Route Parameters

Route parameters are named URL segments that are used to capture the values specified at their position in the URL. The captured values are then made available in the params object on the Request object.

Aurora.get('/user/:id', function(req, res)
    res.send("User ID: " .. req.params.id)
end)