- Run
npm installto install all dependencies. - Create .env file and set
DATABASE_URLvariable with your database URL. - Run
npx prisma generateto load your environtment variable to prisma. - Run
npx prisma migrate devto migrate prisma schema to your database. - Run
npm run startto start the server.
- To start in development mode (using nodemon), run
npm run start:dev - To fix code using Eslint, run
npm run lint:fix - To autoformat code using Prettier, run
npm run format:fix
There's a Postman Collection and Environtment that you can access here to test this API. Most of the HTTP calls have their own testing script. Make sure to use the environment before you run the collection.
POST /api/users= Create new user. Name and email must be unique. Sample request body:
{
"name": "nama",
"email": "email@email.com",
"dateofbirth": "2002-12-21"
}
Sample response body:
{
"id": "user-uuid-uuid",
"name": "nama",
"email": "email@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
}
GET /api/users= Get all created users. Sample response body:
{
"users": [
{
"id": "user-1",
"name": "nama",
"email": "nama@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
},
{
"id": "user-2",
"name": "nama2",
"email": "nama2@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
}
]
}
GET /api/users/:id= Get created users with specified Id. This API is server-side cached for 1 hour. Sample response body:
{
"id": "user-id1",
"name": "nama1",
"email": "nama1@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
}
GET /api/users?name=name&email=email= Get all created users with specified name and/or email. Sample response body:
{
"users": [
{
"id": "user-1",
"name": "nama",
"email": "nama@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
}
]
}
PUT /api/users/:Id= Update user with specified Id. Name and email must be unique. Sample request body:
{
"name": "nama-updated",
"email": "email@email.com",
"dateofbirth": "2002-12-21"
}
Sample response body:
{
"id": "user-uuid-uuid",
"name": "nama-updated",
"email": "email@email.com",
"dateofbirth": "2002-12-21T00:00:00.000Z"
}
-
DELETE /api/users/:Id= Delete user with specified Id -
Common Errors
- Register/Update name and/or email with the same name and/or email as other user.
{ "message": "User name or email is already used!" }- Missing field(s) on request body
{ "message": "\"<field-name>\" is required" }- Requested user with specified Id not found
{ "message": "User not found!" }