An API to create posts for an user. This project is used to test the compatibility of Nest with Bun. You will find the Node.js version in the main branch and the version for Bun in the branch migrate-to-bun.
This repository is based on the NestJS Starter Kit [v2].
This API includes the following features:
Feature | Info | Progress |
---|---|---|
Authentication | JWT | Done |
Authorization | RBAC (Role based) | Done |
ORM Integration | TypeORM | Done |
Logging | winston | Done |
Request Validation | class-validator | Done |
Validations | Joi | Done |
Install the dependencies
npm install
Generate JWT public and private key pair for jwt authentication.
ssh-keygen -t rsa -b 2048 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
You may save these key files in ./local
directory as it is ignored in git.
Start an PostgreSQL server locally and create a new database: PostgreSQL Documentation
Create a .env file with the following properties:
JWT_PUBLIC_KEY_BASE64="<public key>"
APP_PORT=<port>
DB_HOST=<db host>
DB_PORT=<db port>
DB_NAME=<db name>
DB_USER=<db user>
DB_PASS=<db password>
JWT_ACCESS_TOKEN_EXP_IN_SEC=<seconds>
JWT_REFRESH_TOKEN_EXP_IN_SEC=<seconds>
DEFAULT_ADMIN_USER_PASSWORD=<password>
Encode keys to base64:
base64 -i local/jwtRS256.key
base64 -i local/jwtRS256.key.pub
The Postgres server must berunning for the app to work
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Property | Value |
---|---|
Endpoint | /api/v1/auth/register |
Method | POST |
Body | User |
Response | Registered User |
{
"name": "<full name>",
"username": "<username>",
"password": "<password>",
"roles": "<roles: admin / user>",
"email": "<email>",
"isAccountDisabled": <boolean>
}
Property | Value |
---|---|
Endpoint | /api/v1/auth/login |
Method | POST |
Body | Username & Password |
Response | Tokens |
{
"username": "<username>",
"password": "<password>"
}
Property | Value |
---|---|
Endpoint | /api/v1/auth/refresh-token |
Method | POST |
Body | Refresh Token |
Response | Tokens |
{
"refreshToken": "<token>"
}
You have to supply a valid Bearer Token for the authorization check to work. If you don't have an user, please register first.
Property | Value |
---|---|
Endpoint | /api/v1/users/me |
Method | GET |
Body | - |
Response | User |
Property | Value |
---|---|
Endpoint | /api/v1/users |
Method | GET |
Body | - |
Response | All Users |
Property | Value |
---|---|
Endpoint | /api/v1/users/{id} |
Method | GET |
Body | - |
Response | User |
Property | Value |
---|---|
Endpoint | /api/v1/articles/{id} |
Method | PATCH |
Body | Username & Password |
Response | User |
{
"name": "<name>",
"password": "<password>"
}
You have to supply a valid Bearer Token for the authorization check to work. If you don't have an user, please register first.
Property | Value |
---|---|
Endpoint | /api/v1/articles |
Method | POST |
Body | Article |
Response | Created Article |
{
"title": "<title>",
"post": "<post>"
}
Property | Value |
---|---|
Endpoint | /api/v1/articles |
Method | GET |
Body | - |
Response | All Articles |
Property | Value |
---|---|
Endpoint | /api/v1/articles/{id} |
Method | GET |
Body | - |
Response | Article |
Property | Value |
---|---|
Endpoint | /api/v1/articles/{id} |
Method | PATCH |
Body | Article |
Response | Updated Book |
{
"title": "<title>",
"post": "<post>"
}
Property | Value |
---|---|
Endpoint | /api/v1/articles/{id} |
Method | DELETE |
Body | - |
Response | - |