/E_Commerce

Primary LanguageJavaScript

ecommerce

customer site

  • RESTful endpoint for E-commerce CRUD operation
  • JSON formatted response

URL

https://e-commerce-m96.web.app/

RESTful endpoints

POST /register

user Register

Request Header

not needed

Request Body

{
  name : <posted-name>,
  email : <posted-email>,
  password : <posted-password>,
  role : <'admin' by default>
}

Response (201)

[
    {
        "access_token": "<When you register you automatically login and get access_token>"
    }
]

Response (400 - Bad Request)

{
  "errorCode" = 'VALIDATION_ERROR'
  "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /login

user Login

Request Header

not needed

Request Body

{
  email : <posted-email>,
  password : <posted-password>
}

Response (200)

[
    {
    "access_token": <This access token generated automatically when you Log-in>
    }
]

Response (400 - Bad Request)

{
  "errorCode" = 'INVALID_EMAIL_OR_PASSWORD'
  "message": "<returned error message>"
}

Response (403 - Forbidden Access)

{
  "errorCode" = 'FORBIDDEN_ACCESS'
  "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /product

Get all Product

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

not needed

Response (200)

[
    {
        "id": 1 <automatically created by database>,
        "name": "Quiet" <Just an example>,
        "image_url": "http://QuietBySusanCain.jpg" <Fake image Url>,
        "price": 60000 <posted price of Product>,
        "stock": 9 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-13T23:01:56.602Z",
        "updatedAt": "2020-05-13T23:01:56.602Z"
    },
    {
        "id": 17 <automatically created by database>,
        "name": "Sophie's World" <Just an example>,
        "image_url": "http://sophiesworld.jpg" <Fake image Url>,
        "price": 2356 <posted price of Product>,
        "stock": 1425451 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T13:14:23.442Z",
        "updatedAt": "2020-05-15T16:19:22.981Z"
    },
    {
        "id": 18 <automatically created by database>,
        "name": "The Psychology Book: Big Ideas Simply Explained" <Just an example>,
        "image_url": "http://ThePsychologyBookBigIdeasSimplyExplained.jpg" <Fake image Url>,
        "price": 35346 <posted price of Product>,
        "stock": 75675 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T14:59:14.634Z",
        "updatedAt": "2020-05-15T16:19:35.676Z"
    }
]

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /product/:id

Find Product by id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

not needed

Request Params

{ id: ':id' }

Response (200 - Ok)

[
    {
        "id": 1 <automatically created by database>,
        "name": "Quiet" <Just an example>,
        "image_url": "http://QuietBySusanCain.jpg" <Fake image Url>,
        "price": 60000 <posted price of Product>,
        "stock": 9 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-13T23:01:56.602Z",
        "updatedAt": "2020-05-13T23:01:56.602Z"
    },
]

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
    "message": "Product not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /product

Post new product

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

{
  "name": "<posted name of Product>",
  "image_url": "<posted image of Product>"
  "price": "<posted price of Product>",
  "stock": "<posted stock of Product>"
  "category": "<posted category of Product>"
}

Request userData

{
    "role" : <role after access_token decoded by authentication>,
}

Response (201 - Created)

{
    "id": 21 <automatically created by database>,
    "name": "The Highly Sensitive Person: How to Thrive When the World Overwhelms You" <Just an example>,
    "image_url": "http://HspByElaineNAron.jpg" <Fake image Url>,
    "price": 50000 <posted price of Product>,
    "stock": 4 <posted stock of Product>,
    "category": "Psikologi" <posted category of Product>,
    "updatedAt": "2020-05-16T02:02:02.946Z",
    "createdAt": "2020-05-16T02:02:02.946Z"
}

Response (400 - Bad Request)

{
    "errorCode": "VALIDATION_ERROR",
    "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

PUT /product/:id

Update product by Id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

{
  "name": "<posted name of Product>",
  "image_url": "<posted image of Product>"
  "price": "<posted price of Product>",
  "stock": "<posted stock of Product>"
}

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    "name": "Product Succesfully Updated"
}

Response (400 - Bad Request)

{
    "errorCode": "VALIDATION_ERROR",
    "message": "<returned error message>"
}

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
    "message": "Product not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

DELETE /product/:id

Delete product by id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

not needed

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    "message": "Product successfully deleted"
}

Response (404 - Not Found)

{
    "message": "Product not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /customer/register

user Register

Request Header

not needed

Request Body

{
  name : <posted-name>,
  email : <posted-email>,
  password : <posted-password>,
  role : <'customer' by default>
}

Response (201)

[
    {
        "access_token": "<When you register you automatically login and get access_token>"
    }
]

Response (400 - Bad Request)

{
  "errorCode" = 'VALIDATION_ERROR'
  "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /customer/login

user Login

Request Header

not needed

Request Body

{
  email : <posted-email>,
  password : <posted-password>
}

Response (200)

[
    {
    "access_token": <This access token generated automatically when you Log-in>
    }
]

Response (400 - Bad Request)

{
  "errorCode" = 'INVALID_EMAIL_OR_PASSWORD'
  "message": "<returned error message>"
}

Response (403 - Forbidden Access)

{
  "errorCode" = 'FORBIDDEN_ACCESS'
  "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /productCustomer

Get all Product for User/Customer

Request Body

not needed

Response (200)

[
    {
        "id": 1 <automatically created by database>,
        "name": "Quiet" <Just an example>,
        "image_url": "http://QuietBySusanCain.jpg" <Fake image Url>,
        "price": 60000 <posted price of Product>,
        "stock": 9 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-13T23:01:56.602Z",
        "updatedAt": "2020-05-13T23:01:56.602Z"
    },
    {
        "id": 17 <automatically created by database>,
        "name": "Sophie's World" <Just an example>,
        "image_url": "http://sophiesworld.jpg" <Fake image Url>,
        "price": 2356 <posted price of Product>,
        "stock": 1425451 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T13:14:23.442Z",
        "updatedAt": "2020-05-15T16:19:22.981Z"
    },
    {
        "id": 18 <automatically created by database>,
        "name": "The Psychology Book: Big Ideas Simply Explained" <Just an example>,
        "image_url": "http://ThePsychologyBookBigIdeasSimplyExplained.jpg" <Fake image Url>,
        "price": 35346 <posted price of Product>,
        "stock": 75675 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T14:59:14.634Z",
        "updatedAt": "2020-05-15T16:19:35.676Z"
    }
]

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /productCustomer/search/:name

Get all Product for User/Customer

Request Body

not needed

Request Params

{ name: ':name' }
// assuming :name = "a" so it will return any product that have "a" in their title

Response (200)

[
    {
        "id": 1 <automatically created by database>,
        "name": "a" <Just an example>,
        "image_url": "http://a.jpg" <Fake image Url>,
        "price": 60000 <posted price of Product>,
        "stock": 9 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-13T23:01:56.602Z",
        "updatedAt": "2020-05-13T23:01:56.602Z"
    },
    {
        "id": 17 <automatically created by database>,
        "name": "bac" <Just an example>,
        "image_url": "http://bac.jpg" <Fake image Url>,
        "price": 2356 <posted price of Product>,
        "stock": 1425451 <posted stock of Product>,
        "category": "Hukum" <posted category of Product>,
        "createdAt": "2020-05-15T13:14:23.442Z",
        "updatedAt": "2020-05-15T16:19:22.981Z"
    },
    {
        "id": 18 <automatically created by database>,
        "name": "fga" <Just an example>,
        "image_url": "http://fga.jpg" <Fake image Url>,
        "price": 35346 <posted price of Product>,
        "stock": 75675 <posted stock of Product>,
        "category": "Kuliner" <posted category of Product>,
        "createdAt": "2020-05-15T14:59:14.634Z",
        "updatedAt": "2020-05-15T16:19:35.676Z"
    }
]

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /productCustomer/category/:category

Get all Product for User/Customer

Request Body

not needed

Request Params

{ category: ':category' }
// assuming :category = "Psikologi" so it will return any product with category "Psikologi"

Response (200)

[
    {
        "id": 1 <automatically created by database>,
        "name": "a" <Just an example>,
        "image_url": "http://a.jpg" <Fake image Url>,
        "price": 60000 <posted price of Product>,
        "stock": 9 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-13T23:01:56.602Z",
        "updatedAt": "2020-05-13T23:01:56.602Z"
    },
    {
        "id": 17 <automatically created by database>,
        "name": "bac" <Just an example>,
        "image_url": "http://bac.jpg" <Fake image Url>,
        "price": 2356 <posted price of Product>,
        "stock": 1425451 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T13:14:23.442Z",
        "updatedAt": "2020-05-15T16:19:22.981Z"
    },
    {
        "id": 18 <automatically created by database>,
        "name": "fga" <Just an example>,
        "image_url": "http://fga.jpg" <Fake image Url>,
        "price": 35346 <posted price of Product>,
        "stock": 75675 <posted stock of Product>,
        "category": "Psikologi" <posted category of Product>,
        "createdAt": "2020-05-15T14:59:14.634Z",
        "updatedAt": "2020-05-15T16:19:35.676Z"
    }
]

Response (404 - Product_Not_Found)

{
  "errorCode" = 'DATA_NOT_FOUND'
  "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /banner

Get all Banner data

Request Body

not needed

Response (200)

[
    {
        "id": 1 <automatically created by database>,
        "name": "buku" <Just an example>,
        "image_url": "https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=80" <Just an example>,
        "createdAt": "2020-05-25T15:39:36.773Z",
        "updatedAt": "2020-05-25T15:39:36.773Z"
    },
    {
        "id": 2 <automatically created by database>,
        "name": "buku2" <Just an example>,
        "image_url": "https://images.unsplash.com/photo-1542086260-ddb62f405c8b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2050&q=100" <Just an example>,
        "createdAt": "2020-05-25T15:57:27.103Z",
        "updatedAt": "2020-06-03T17:56:01.799Z"
    },
    {
        "id": 4 <automatically created by database>,
        "name": "buku3" <Just an example>,
        "image_url": "https://images.unsplash.com/photo-1551029506-0807df4e2031?ixlib=rb-1.2.1&auto=format&fit=crop&w=1191&q=100" <Just an example>,
        "createdAt": "2020-05-25T16:35:33.488Z",
        "updatedAt": "2020-05-25T16:48:46.794Z"
    }
]

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /banner

Post new banner

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

{
  "name": "<posted name of Banner>",
  "image_url": "<posted image of Banner>"
}

Request userData

{
    "role" : <role after access_token decoded by authentication>,
}

Response (201 - Created)

{
    "id": 6 <automatically created by database>,
    "name": "buku3" <posted name of Banner>,
    "image_url": "https://images.unsplash.com/photo-1546700908-f2001b40cf76?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3075&q=100" <posted image of Banner>,
    "updatedAt": "2020-06-03T18:14:30.380Z",
    "createdAt": "2020-06-03T18:14:30.380Z"
}

Response (400 - Bad Request)

{
    "errorCode": "VALIDATION_ERROR",
    "message": "<returned error message>"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /banner/:id

Find Banner by id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

not needed

Request Params

{ id: ':id' }
// assuming :id = 6

Response (200 - Ok)

[
    "id": 6 <automatically created by database>,
    "name": "buku3" <posted name of Banner>,
    "image_url": "https://images.unsplash.com/photo-1546700908-f2001b40cf76?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3075&q=100" <posted image of Banner>,
    "updatedAt": "2020-06-03T18:14:30.380Z",
    "createdAt": "2020-06-03T18:14:30.380Z"
]

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
    "message": "Product not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

PUT /banner/:id

Update Banner by Id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

{
  "name": "<posted name of Banner>",
  "image_url": "<posted image of Banner>"
}

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    "name": "Banner Succesfully Updated"
}

Response (400 - Bad Request)

{
    "errorCode": "VALIDATION_ERROR",
    "message": "<returned error message>"
}

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
    "message": "Product not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

DELETE /banner/:id

Delete banner by id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

not needed

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    "name": "Banner successfully deleted"
}

Response (404 - Not Found)

{
    "message": "Banner not found"
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

GET /cart

Get all Cart data

Request Body

not needed

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Response (200)

[
    {
        "id": 6 <automatically created by database>,
        "name": "yza" <got from database>,
        "image_url": "https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=100" <got from database>,
        "price": 123 <got from database>,
        "stock": 88 <got from database>,
        "category": "Kamus" <got from database>,
        "UserId": 19 <got from database>,
        "createdAt": "2020-06-02T18:19:04.721Z",
        "updatedAt": "2020-06-03T18:43:17.850Z"
    },
    {
        "id": 8 <automatically created by database>,
        "name": "bcd" <got from database>,
        "image_url": "https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=100" <got from database>,
        "price": 456 <got from database>,
        "stock": 402 <got from database>,
        "category": "Agama" <got from database>,
        "UserId": 19 <got from database>,
        "createdAt": "2020-06-03T04:01:37.064Z",
        "updatedAt": "2020-06-03T10:28:40.829Z"
    },
    {
        "id": 13 <automatically created by database>,
        "name": "def" <got from database>,
        "image_url": "https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=100" <got from database>,
        "price": 456 <got from database>,
        "stock": 320 <got from database>,
        "category": "Romance" <got from database>,
        "UserId": 19 <got from database>,
        "createdAt": "2020-06-03T07:47:23.529Z",
        "updatedAt": "2020-06-03T10:30:01.282Z"
    },
    {
        "id": 10 <automatically created by database>,
        "name": "stu" <got from database>,
        "image_url": "https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=100" <got from database>,
        "price": 123 <got from database>,
        "stock": 12 <got from database>,
        "category": "Anak-Anak" <got from database>,
        "UserId": 19 <got from database>,
        "createdAt": "2020-06-03T07:03:05.890Z",
        "updatedAt": "2020-06-03T11:15:04.720Z"
    }
]

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

POST /cart

Post new product to Cart

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Body

{
  "name": "<posted name of Product>",
  "image_url": "<posted image of Product>",
  "price": "<posted price of Product>",
  "stock": "<posted stock of Product>",
  "category": "<posted category of Product>",
  "buy": "<amount that want to added to cart>",
}

Request userData

{
    "id" : <id after access_token decoded by authentication>,
}

// If in Cart posted product not exist yet Response (201 - Created)

{
    "id": 21 <automatically created by database>,
    "name": "The Highly Sensitive Person: How to Thrive When the World Overwhelms You" <Just an example>,
    "image_url": "http://HspByElaineNAron.jpg" <Fake image Url>,
    "price": 50000 <posted price of Product>,
    "stock": 4 <posted stock of Product>,
    "category": "Psikologi" <posted category of Product>,
    "updatedAt": "2020-05-16T02:02:02.946Z",
    "createdAt": "2020-05-16T02:02:02.946Z"
}

// If in Cart posted product exist Response (200 - Updated)

{ name: 'Cart succesfully updated' }

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

PUT /cart/:id

Update product in cart by Id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

{
  "name": "<posted name of Product>",
  "image_url": "<posted image of Product>"
  "price": "<posted price of Product>",
  "stock": "<posted stock of Product>"
  "buy": "<amount that want to added to cart>",
}

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    name: 'Cart succesfully updated'
}

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
     "name": 'Product not found'
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}

PUT /cart/decrease/:id

Update decrease product(s) in cart by id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in/Register>
}

Request Body

{
  "buy": "<amount to decrease stock in cart>",
}

Request Params

{ id: ':id' }

Response (200 - Ok)

{
    name: <name of updated product in cart>
}

Response (404 - Not Found)

{
    "errorCode": "DATA_NOT_FOUND",
     "name": 'Product not found'
}

Response (500 - Internal Server Error)

{
  "message": "<returned error message>"
}