Usages
How to create a basic avleon application.
There are two ways to design your application: Controller based and
Route method based. They can be mixed in the same app.
Using Controller
Controllers group related routes and can take dependencies through the constructor. This is the approach the CLI scaffolds.
See Controller for parameters, REST resources and error handling.
Using Inline Route
For small apps, register handlers directly on the app with mapGet, mapPost,
mapPut and mapDelete:
Handlers receive the request and response, and returning an object sends JSON:
Inline routes return a chainable object for middleware and OpenAPI metadata:
Returning responses
Returning an object or array sends JSON; returning a string sends it as-is.
To control the status code or headers, throw an HttpExceptions error:
Running the app
run takes an optional port, defaulting to 4000:
Read the port from the environment to make it configurable:
Next steps
- Controller — routes, parameters, REST resources
- Middleware — request pipeline
- Database — TypeORM and Knex
- OpenAPI — API documentation