This is the boilerplate for creating an API server in AdonisJs, it comes pre-configured with.
- Bodyparser
- Authentication
- CORS
- Lucid ORM
- Migrations and seeds
Use the adonis command to install the blueprint
adonis new yardstick --api-only
or manually clone the repo and then run npm install
.
Run the following command to run startup migrations.
adonis migration:run
Instal Adonis:
$ npm i -g @adonisjs/cli
create API project with name sistac-api (API de Sistema de Agendamento de Compromissos):
$ adonis new sistac-api --api-only
Run project:
$ adonis serve --dev
-
Install eslint global:
npm install eslint -g
-
Run:
eslint --init
use stardard styleguide and generate by CLI commandeslintrc.json
-
Inside eslintrc.json add a configuration to prop globals:
"use": true
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"use": true
},
Use is a global functoins, its is not declared, then Eslint shold trown a error.
Editor config .editorconfig come with default configuratoin when execute adonis new
Inside of the config/database.js
there a step-by-step how to configure database.
Choice a database and install the dependecy npm i --save pg
Start docker container postgres: docker container start ID
When the database was created and is running, then run this command:
adonis migration:run
, for create the tables basics for user and tokens.
-
User:
adonis make:controller User
, it should create a file inside folder Controllers/Http/UserController.js, after you choice http type. -
Authentication JWT
-
User:
adonis make:controller Session
, it should create a file inside folder Controllers/Http/SessionController.js, after you choice http type. -
Recover Password
adonis make:controller ForgotPassword
, it should create a file inside folder Controllers/Http/ForgotPassword.js, after you choice http type.
Install (see the doc)
adonis install @adonis/mail
Next, register the provider inside start/app.js
file.
const providers = {
'@adonisjs/mail/providers/MailProvider'
}