Built with NodeJs using the ExpressJs Framework. Express.js is a web application framework for Node.js. More about Express
Point of Sales APP API is an API that allow the users to read product and category information data from database. Point of Sales APP API also allow users to read, create, update and delete a product and its category information into/from database.
- Node.js - Download and Install Node.js - Simple bash script to manage multiple active node.js versions.
- Nodemon - Download and Install Nodemon - nodemon is a tool that automatically restarting the node application when file changes in the directory are detected.
- Express JS - Download and Install Express JS - web framework for Node.js
$ git clone https://github.com/ardabudi/Posapps_backend
$ cd Posapps_backend
$ npm install
Open .env file on your favorite code editor, and copy paste this code below :
PORT = 8001
DB_HOST = 'localhost'
DB_USER = 'root'
DB_PASSWORD = ''
DB_NAME = 'note'
JWT_KEY = 'note'
$ npm start
All API requests are made by sending a secure HTTPS request using one of the following methods, depending on the action being taken:
GET
Get a resource or list of resourcesPOST
Create a resourcePATCH
Update a resourceDELETE
Delete a resource
IMPORTANT! All endpoint except Login and Register must have header :
- user-id :
id user
- token:
token
- Register user
- Request :
POST localhost:8001/user/register
{ "name": "arda", "password": "123", "email": "arda@gmail.com" }
- Response :
{ "status": 200, "result": { "fieldCount": 0, "affectedRows": 1, "insertId": 14, "serverStatus": 2, "warningCount": 0, "message": "", "protocol41": true, "changedRows": 0 }
- Request :
} ```
- Login User
- Request :
POST localhost:8001/user/login
{ "email": "arda@gmail.com", "password": "123" }
- Response :
{ "id": 14, "name": "arda", "email": "arda@gmail.com", "created_at": "2020-02-29T03:56:45.000Z", "updated_at": "2020-02-29T03:56:45.000Z", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFyZGFAZ21haWwuY29tIiwiaWQiOjE0LCJpYXQiOjE1ODI5NDg3MDcsImV4cCI6MTU4Mjk1NTkwN30.Eh-0UzRaDUdfQLrp4Xl9ZkGl9UPG7Q9zpSJ8R7vUDVw"
- Request :
} ```
1. Read All Category
- Request :
GET localhost:8001/category
- Response :
{
"status": 200,
"result": [
{
"id": 1,
"name": "Food",
"created_at": "2020-02-16T10:53:39.000Z",
"updated_at": "2020-02-16T10:53:39.000Z"
},
{
"id": 2,
"name": "Drink",
"created_at": "2020-02-16T10:53:39.000Z",
"updated_at": "2020-02-16T10:53:39.000Z"
}
]
}
2. Read a category
- Request :
GET localhost:8001/category/1
- Response :
{
"status": 200,
"result": [
{
"id": 1,
"name": "Food",
"created_at": "2020-02-16T10:53:39.000Z",
"updated_at": "2020-02-16T10:53:39.000Z"
}
]
}
3. Create a category
- Request :
POST localhost:8001/category
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 2,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
}
4. Update a category
(Need Verification by ID Category)
- Request :
PATCH localhost:8001/category/2
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "(Rows matched: 1 Changed: 1 Warnings: 0",
"protocol41": true,
"changedRows": 1
}
}
5. Delete a category
- Request :
DELETE localhost:8001/category/2
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
}
1. Read all product
- Request :
GET localhost:8001/product
- Response :
{
"status": 200,
"result": [
{
"id": 53,
"name": "Cappucino",
"description": "Coffe",
"image": "http://localhost:8001/uploads/cappucino.jpg",
"price": 14000,
"stock": 40,
"category": "Drink",
"created_at": "2020-02-26T07:30:55.000Z",
"updated_at": "2020-02-26T07:30:55.000Z"
},
{
"id": 55,
"name": "Coffe Latte",
"description": "coffe",
"image": "http://localhost:8001/uploads/Coffe Latte.png",
"price": 15000,
"stock": 30,
"category": "Drink",
"created_at": "2020-02-26T09:06:50.000Z",
"updated_at": "2020-02-26T09:06:50.000Z"
},
{
"id": 61,
"name": "Steak Sapi",
"description": "Steak",
"image": "http://localhost:8001/uploads/steaksapi.jpg",
"price": 24000,
"stock": 30,
"category": "Food",
"created_at": "2020-02-26T16:03:59.000Z",
"updated_at": "2020-02-26T16:03:59.000Z"
}
]
}
2. Read a product
- Request :
GET localhost:8001/product/97
- Response :
{
"status": 200,
"result": [
{
"id": 97,
"name": "Steak Ayam",
"description": "Steak Ayam",
"image": "http://localhost:8001/uploads/image-6.jpg",
"price": 21000,
"stock": 30,
"category": "Food",
"created_at": "2020-02-28T14:08:38.000Z",
"updated_at": "2020-02-29T01:42:18.000Z"
}
]
}
3. Create a product
- Request :
POST localhost:8001/product
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 98,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
}
4. Update product
- Request :
PATCH localhost:8001/product/97
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "(Rows matched: 1 Changed: 1 Warnings: 0",
"protocol41": true,
"changedRows": 1
}
}
5. Delete product
- Request :
DELETE localhost:8001/product/97
- Response :
{
"status": 200,
"result": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
}
Feature | Request |
---|---|
Search by name |
Request : GET /product/?search=nasi |
Pagination in product |
Request : GET product/?page=1&limit=4 |
Sort product by name |
Request : GET product/?by=name&sort=DESC |
Sort product by category |
Request : GET product/?by=category&sort=ASC |
Sort product by date update |
Request : GET product/?by=date_update&sort=DESC |