Online store API developed with Node.js + Express. User authorization handled with Passport.js Integrated with Stripe for handling payments. Products data is stored in Mongo DB.
Requires specific environment variables to run:
MONGOLAB_URI=
SERVER_PORT=
STRIPE_SECRET_KEY=
CLIENT_URL=
Installing dependencies:
npm install
For production run:
npm start
For development it can be also run with script:
npm run dev
URL: /products/
Method: GET
Success Response Code: 200
Sample response:
[
{
"name": "Snake 3D",
"image": "/images/products/snake.png",
"description": "description",
"rating": 4,
"price": "99.99",
"productId": 1,
"category": "games",
"subcategory": "ps4",
"badges": [
"Best Seller"
]
},
...
]
URL: /products/categories
Method: GET
Success Response Code: 200
Sample response:
[
{
"computers": {
"display": "Computers",
"subcategories": {
"laptops": "Laptops",
"tablets": "Tablets",
"peripherials": "Peripherials",
"accessories": "Accessories"
}
}
...
]
URL: /products/:id
Method: GET
URL Params: id=[integer]
Success Response Code: 200
Sample response:
{
"name": "Snake 3D",
"image": "/images/products/snake.png",
"description": "ante sollicitudin",
"rating": 4,
"price": "99.99",
"productId": 1,
"category": "games",
"subcategory": "ps4",
"badges": [
"Best Seller"
]
}
URL: /users/register
Method: POST
Request body:
{
"username": "test2",
"email": "test2@test.com",
"password": "secret"
}
Success Response Code: 201
URL: /cart/:userid
Method: POST
Request body:
{
"productId": "1",
"quantity": "1"
}
Success Response Code: 201
Sample response:
{
"productId": 10,
"username": "test2",
"quantity": 1,
}
**To remove product from cart - send a request with negative quantity. Example:
{
"productId": 1,
"quantity": -1
}
URL: /cart/:userid
Method: DELETE
Success Response Code: 200
URL: /cart/:userid
Method: GET
Success Response Code: 200
Sample response:
[
{
"productId": 1,
"username": "test2",
"quantity": 5,
}
]
There are integration tests implemented for Online Store API using:
- Supertest
When running tests with CI and XML report is expected run:
npm test
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.