@adonisjs/http-server package and includes additional features specifically designed for AdonisJS applications.
What’s included
The HTTP module provides the following core features:- Routing: Define routes with support for HTTP methods, parameters, middleware, and route groups
- Controllers: Organize your application logic into controller classes
- Middleware: Process requests before they reach your route handlers
- Request handling: Access and validate incoming request data
- Response handling: Send responses in various formats (JSON, HTML, files, etc.)
- Request validation: Validate request data using VineJS validators
- URL builder: Generate URLs for your named routes
Basic usage
Here’s a simple example of defining routes and handling requests:HttpContext
Every route handler receives anHttpContext object, which bundles together the request, response, and other useful properties:
HttpContext object includes:
request: The Request object for accessing incoming dataresponse: The Response object for sending responsesparams: URL parameters from the routeauth: Authentication helpers (when auth is configured)session: Session management (when session is configured)- And more…
Project structure
HTTP-related files are typically organized as follows:Next steps
Routing
Learn how to define routes and route groups
Controllers
Organize logic into controller classes
Middleware
Process requests with middleware
Validation
Validate request data with VineJS