This is the third project of the Full Stack Developer course at Acamica.
- Clone the repo
git clone https://github.com/gopherunner/delilah-resto-api.git
- Install NPM packages
cd delilah-resto-api npm install
-
Install MariaDB with Brew:
brew update brew install mariadb
-
After a successful installation, we can start the server and also ensure it autostarts in the future:
brew services start mariadb
-
You should get some feedback from the last command like:
==> Successfully started `mariadb` (label: ...)
-
You must change the root password and secure your installation:
sudo /usr/local/bin/mysql_secure_installation
-
Create an .env file on the root of the project with the following configuration:
APP_PORT=3000 APP_SECRET=s3cr3t DB_HOST=localhost DB_USER=root DB_PASS=<password set for mariadb> DB_NAME=delilah_resto DB_PORT=3306
-
Import the Delilah Resto Database schemas into the DB:
cd delilah-resto-api/db $ mysql -u root -p#### -h localhost < delilah_resto.sql
NOTE: replace the #### with the password you set for the db
-
Start the REST API:
cd delilah-resto-api $ npm start
Check that the REST API is working
[INFO] Connecting to the Database (delilah_resto) on port 3306... [INFO] Connection established! [INFO] Starting Delilah Resto API Server, listening on port 3000
-
Install JSON commandline JQ:
in Mac OS:
brew install jq
- Customer Login and retrieve the Token to use later on
$ TOKEN=$(curl -H "Content-Type: application/json" --request POST -d '{ "username": "admin", "password": "admin" }' \
http://localhost:3000/customers/login | jq -r '.token')
- List all the available Products
$ curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" --request GET http://localhost:3000/products \
| json_pp -json_opt pretty
- List all the available Orders
$ curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" --request GET \
http://localhost:3000/orders | json_pp -json_opt pretty,canonical
POST http://localhost:3000/orders
{
"username": "admin",
"payment_method": "cash",
"products": [
{
"product_id": 2,
"product_qty": 3
},
{
"product_id": 1,
"product_qty": 1
}
]
}
METHOD | ENDPOINT | BODY | HEADER | DESCRIPTION |
---|---|---|---|---|
POST | /customers/register | { username, password, fullname, address, email, phone_number } | Create a new Customer | |
POST | /customers/login | { username, password } | Login Customer and get the Token | |
GET | /customers/orders | { token } | Returns all the orders from the customer | |
PUT | /customers/:id | { adminToken } | Modify an existing Customer |
METHOD | ENDPOINT | BODY | HEADER | DESCRIPTION |
---|---|---|---|---|
POST | /products | { username, password, fullname, address, email, phone_number } | { adminToken } | Create a new Product |
GET | /products | { token } | Return all the Products | |
GET | /products/:id | { token } | Return an specific Product | |
PUT | /products/:id | { product_name, product_detail, product_price, product_photo, active } | { adminToken } | Modify an existing Product |
DELETE | /products/:id | { adminToken } | Deletes an existing Product |
METHOD | ENDPOINT | BODY | HEADER | DESCRIPTION |
---|---|---|---|---|
POST | /orders | { username, payment_method, products } | { token } | Create a new Order |
GET | /orders | { adminToken } | Return all the Orders | |
GET | /orders/:id | { adminToken } | Return an specific Order | |
PUT | /orders/:id | { order_status } | { adminToken } | Modify the status of an existing Order |
DELETE | /orders/:id | { adminToken } | Deletes an existing Order |