- This is the source make simple API for all beginner Frontend Developer
- It's includes
- Lowdb
- ExpressJS Example
- Author:
Khôi Pham
- Bài viết hướng dẫn: https://suntech.edu.vn/api-danh-cho-frontend-developer.sunpost.html
- Video hướng dẫn: https://youtu.be/oiDx9Y6zUts
- Step1: Install NodeJs (https://nodejs.org/en/)
- Step2: Run command
npm install
- Step3: Start server with command:
node index.js
- Run on local: http://localhost:8000/
- Step4: Install Postman for test API: https://www.postman.com/downloads/
baseUrl
: http://localhost:8000
GET
: {baseUrl}/api/products
Parameters
: No
Request body
: No
Response
:
[
.....
{
"name": "Test product 3 (test edit)",
"price": "5000000",
"description": "product 3",
"id": "xWbk1Ck9-ba7uQZZiFxpL"
}
.....
]
GET
: {baseUrl}/api/products/:id
Parameters
: No
Request body
: No
Response
:
{
"name": "Test product name",
"price": "1000000",
"description": "Test product description",
"id": "rovKMQRGxpAUUQet_dE7W"
}
POST
: {baseUrl}/api/products
Parameters
: No
Request body
:
{
"name": "Iphone 12",
"price": "25000000",
"description": "Thông tin chi tiết sản phẩm Iphone 12"
}
Response
:
{
"success": true
}
PUT
: {baseUrl}/api/products/:id
Parameters
: No
Request body
:
{
"name": "Iphone 12",
"price": "25000000",
"description": "Thông tin chi tiết sản phẩm Iphone 12"
}
Response
:
{
"success": true
}
PUT
: {baseUrl}/api/products/:id
Parameters
: No
Request body
:
{
"name": "Iphone 12",
"price": "25000000",
"description": "Thông tin chi tiết sản phẩm Iphone 12"
}
Response
:
{
"success": true
}
GET
: {baseUrl}/api/users
Parameters
: No
Request body
: No
Response
:
[
.....
{
"id": "5YsFNN42B14VYHhpDyizn",
"name": "Administrator",
"email": "admin@gmail.com",
"password": *****
}
.....
]
GET
: {baseUrl}/api/users/:id
Parameters
: No
Request body
: No
Response
:
{
"id": "5YsFNN42B14VYHhpDyizn",
"name": "Administrator",
"email": "admin@gmail.com",
"password": ******
}
POST
: {baseUrl}/api/users
Parameters
: No
Request body
:
{
"name": "Administrator",
"email": "admin@gmail.com",
"password": 123456
}
Response
:
{
"success": true
}
PUT
: {baseUrl}/api/users/:id
Parameters
: No
Request body
:
{
"name": "Test user update",
"email": "userupdate@gmail.com",
"password": 123456
}
Response
:
{
"success": true
}
DELETE
: {baseUrl}/api/users/:id
Parameters
: No
Request body
: No
Response
:
{
"success": true
}
POST
: {baseUrl}/api/login
Parameters
: No
Request body
:
{
"email": "userupdate@gmail.com",
"password": 123456
}
Response
:
{
"user": {
"id": "id",
"name": "Test user update",
"email": "userupdate@gmail.com",
},
token: 'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI....'
}