Like Express, and Fastify.
You define route using method as a building block for your server.
By calling .[method name](path, callback, hook?)
, you attach the route to Elysia, and the library will handle the routing for you.
For example:
Callback run when the request match.
Means when the [GET] request with path '/ping' shall return 'pong' as a response.
You can define with many built-in methods including:
Other methods can be defined by using .route
:
Path parameters can retrieve data from URL.
For example, getting a user id from path (like many social media) is when you may need path parameters.
Path parameters are a variable in a path.
When the pattern matches, the path you named will become available in context.params
, and you can retrieve its value.
Sometimes path parameters are not enough.
Matching anything after some pattern is required, and you can't define them all or its too redundant.
You can use *
to match the rest.