Creating ecommerce-cms
- RESTful endpoint for E-commerce-Cms CRUD operation
- JSON formatted response
https://e-commerce-m96-cms.web.app/
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>"
}
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 (500 - Internal Server Error)
{
"message": "<returned error message>"
}
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>,
"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>,
"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>,
"createdAt": "2020-05-15T14:59:14.634Z",
"updatedAt": "2020-05-15T16:19:35.676Z"
}
]
Response (500 - Internal Server Error)
{
"message": "<returned error message>"
}
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>,
"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 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>"
}
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>,
"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>"
}
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 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>"
}