Aplication Backend For Stock App
This application is used to serve data requests from the Stock-App client application to the server. Built with Node JS, Express JS and MySql
- body parser v.1.19.0
- cors v.2.8.5
- express v.4.17.1
- express fileupload v.1.2.1
- md5 v.2.3.0
- mysql v.2.18.1
- random token v.0.0.8
- nodemon 2.0.13
- Use this command for cloning this repository
git clone https://github.com/or-abdillh/stock-api.git
- Then, use this command
cd stock-api
- Install all dependencies
npm install
- Make sure you have exported the database using this file
./DB/stockAppDB.sql
- Running the mysql services if you use mysql CLI with this command
mysqld_safe
- Before running the server you must setup the configuration connection to your mysql in
./connection/conn.js
- Then, use this command to run server
npm start
- By default the server running on PORT 8080, you can change the PORT in
./server.js
- HOSTNAME :
http://localhost:8080/
-
/
purpose : Testing response from server -
/auth
purpose : login validation
request methodPOST
-
/token
purpose : Token validation
request methodPOST
-
/logout
purpose : Remove TOKEN and create new TOKEN to table User
request methodGET
-
/profile
purpose : Get fullname, amounts of category and products user have
request methodGET
-
/products
purpose : Get all products from table Products
request methodGET
-
/upload
purpose : Upload image to server, path uploaded file/public
request methodPOST
-
/createProduct
purpose : Create new product
request methodPOST
-
/removeFile
purpose : Remove file image from server
request methodDELETE
-
/deleteProduct
purpose : remove product from table Products
request methodDELETE
-
/updateProduct
purpose : update product from table Products
request methodPOST
-
/categorys
purpose : Get all categorys from table Categorys
request methodGET
-
/createCategory
purpose : Create new category
request methodPOST
-
/deleteCategory
purpose : Remove category from table Categorys
request methodDELETE
-
/setUncategorys
purpose : Set name category product to uncategorys after the current category has deleted
request methodPOST
-
/updateCategory
purpose : Update the category from table Categorys
request methodPOST
-
/search/:keyword/:category
purpose : Get products by keyword and category product
request methodGET
-
/changeName
purpose : Update name user
request methodPOST
-
/changePassword
purpose : Change password user
request methodPOST
Every time you make a request there must be a token in the request header as an identifier
import BASE_URL from '../BASE_URL.js'
//Create Headers to save the token
const headers = {
headers: {
token: 'Get the token from auth endpoint'
}
}
axios.get(`${BASE_URL}/products`, headers)
.then(res => {
console.log(res.data)
})
.catch(err => {
console.error(err)
})
- from
/auth
{
"status": 200,
"message": "success",
"results": {
"TOKEN": "7yyxswvcj6ivjp8c0p6tqult94nx3kbjgetb9tpzfs0tug3f9d4cjsdd9f86otohoa7gc369ukyadztalgjbq20vjxwqeno3dp4z"
}
}
- from
/profile
{
"status": 200,
"message": "success",
"results": {
"fullname": "Sandhika Galih",
"products": "45"
"categorys": "5"
}
}
- from
/products
{
"status": 200,
"message": "success",
"results": [
{
"id_product": 76,
"name_product": "Happy Cuan Figma UI Kits",
"price_product": 567000,
"stock_product": 2,
"image_product": "http://localhost:8080/public/product-1635568922040.jpg",
"category_product": "UI",
"last_modified": 1635585093337,
"stock_unit": "pcs"
}
]
}
- Support me with a cup of coffee and other snacks here ..
- Don't forget to give me star in this repository 🙏🏻🙏🏻
- See my other projects on instagram @or_abdillh
Oka R Abdillah
Last edited on : 31/10/2021