This is a simple Adonis API server which implements the following features:
- Bodyparser
- Authentication
- CORS
- Lucid ORM
- Migrations and seeds
- Clone the repository
- Run
npm install
from the project folder - Install Docker >=17.0 if you have not done it yet
- Run
docker-compose up -d
from thedocker
folder (the PostgreSQL and the PgAdmin containers will up) - Create a database called adonisjs in PostgreSQL
- Create a .env file based on the .env.example file
- Install Adonis globally by running
npm i -g @adonisjs/cli
- Run
adonis migration:run
- Run the
adonis serve --dev
- The server will listen on
http://localhost:3333
Use the following routes to test the application:
POST /api/v1/account/register
{
"email: "test@mail.com",
"username": "my_username",
"password": "my_password
}
POST /api/v1/account/login
{
"email: "test@mail.com",
"password": "my_password
}
RESPONSE
{
"type": "bearer",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsImlhdCI6MTU3ODcxNDE0MX0.F0eM7WsO8aQk-XrLL8s-0Jv6iFNgQ1PUnYGgaWithSc",
"refreshToken": null
}
POST /api/v1/posts/create
HEADER
Authorization: bearer USER_JWT_TOKEN
BODY
{
"title": "The First Post"
}
GET /api/v1/posts/:id
HEADER
Authorization: bearer USER_JWT_TOKEN
POST /api/v1/posts
HEADER
Authorization: bearer USER_JWT_TOKEN
POST /api/v1/posts/:id/delete
HEADER
Authorization: bearer USER_JWT_TOKEN