Giter Club home page Giter Club logo

delilah-resto-api's Introduction

Delilah Resto REST API

This is the third project of the Full Stack Developer course at Acamica.

Procedure

Installation

  1. Clone the repo
    git clone https://github.com/gopherunner/delilah-resto-api.git
  2. Install NPM packages
    cd delilah-resto-api
    npm install

Install & configure the MySQL (MariaDB) database (in this example I did it for MacOS)

  1. Install MariaDB with Brew:

    brew update
    brew install mariadb
  2. After a successful installation, we can start the server and also ensure it autostarts in the future:

    brew services start mariadb
  3. You should get some feedback from the last command like:

    ==> Successfully started `mariadb` (label: ...)
  4. You must change the root password and secure your installation:

    sudo /usr/local/bin/mysql_secure_installation
  5. 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
  6. 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

  7. 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
  8. Install JSON commandline JQ:

    in Mac OS:

    brew install jq

Examples with cURL

  • 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

Postman examples

POST    http://localhost:3000/orders
{
    "username": "admin",
    "payment_method": "cash",
    "products": [
        {
            "product_id": 2,
            "product_qty": 3
        },
        {
            "product_id": 1,
            "product_qty": 1
        }
    ]
}

Endpoints

Customers

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

Products

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

Orders

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

delilah-resto-api's People

Contributors

gopherunner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.