Contents
AdonisJS
A full-featured framework in the spirit of Laravel: routes, controllers, the Lucid ORM, Edge templates and auth.
1.Getting started
- What AdonisJS isWhy you need the AdonisJS framework, what it consists of and which path a request takes.
- Creating a projectHow to create an AdonisJS project from a starter kit, run it and what lives in its folders.
- The Ace consolenode ace commands: running the server, creating files, installing packages and writing your own command.
- Configuration and environment variablesThe .env file, variable checks in start/env.ts and the settings files in the config folder.
2.Routes and controllers
- RoutesHow to connect a page address to code in start/routes.ts and which HTTP methods exist.
- Route parametersVariable parts of an address: required and optional parameters and checking their format.
- Named routes and groupsHow to name a route, build links by name and combine routes into groups with a shared prefix.
- ControllersHow to move request handling out of the routes file into controller classes and attach them to routes.
- The request context: request and responseWhat the HttpContext object holds: reading request data with request and sending a response with response.
3.Edge templates
- Edge templatesHow to render an HTML page from a controller: .edge files, printing variables, conditions and loops.
- Page layout and partialsShared markup for all pages through a layout component, slots and partials included with @include.
- Edge componentsRepeated page blocks as components: props, the default slot and named slots.
- Static files and ViteWhere to keep images and icons, how to include CSS and JavaScript through Vite and the @vite tag.
4.Database
- Connecting a databaseInstalling the Lucid ORM, the settings in config/database.ts and connecting to SQLite or PostgreSQL.
- MigrationsHow to describe database tables in code and apply or roll back changes with Ace commands.
- Lucid modelsWorking with tables through model classes: describing columns, creating, reading, updating and deleting records.
- Querying with LucidThe model query builder: where conditions, ordering, limits, pagination and counting.
- Relationships between modelshasMany and belongsTo relationships with posts and comments, preloading and creating related records.
- Seeders and factoriesHow to fill the database with initial and test data: seeders, model factories and related records.
5.Forms and users
- Validation with VineJSChecking form data before saving: VineJS validators, rules and error messages.
- Forms, CSRF and flash messagesThe add-post form: CSRF protection, showing validation errors, old field values and a success message.
- SessionsHow to keep a visitor's data between requests: session methods, drivers and the settings in config/session.ts.
- AuthenticationUser sign-up, login and logout with the session guard of the @adonisjs/auth package.
- Authorization with BouncerHow to check user permissions: Bouncer abilities and policies, checks in the controller and in the template.
- MiddlewareCode that runs before and after a route handler: creating middleware, the stacks in start/kernel.ts and protecting route groups.
6.Growing the app
- File uploads and DriveHow to receive a file from a form, check its size and type and save it with the Drive package.
- Sending emailThe @adonisjs/mail package: SMTP setup, an email with an Edge template, sending in the background and mail classes.
- Events and listenersHow to separate side effects from the controller: event classes, listeners and registering them in start/events.ts.
- A JSON API and access tokensAPI routes that return JSON, issuing access tokens and protecting routes with the access_tokens guard.
- Error handlingThe global exception handler app/exceptions/handler.ts, 404 and 500 error pages and custom exceptions.
- Testing with JapaFunctional tests for pages and the API: the node ace test command, the HTTP client, the database in tests and logging in a user.
- DeploymentBuilding the project with node ace build, running build/bin/server.js, environment variables and migrations on the server.