This project was bootstrapped with saeed taherifard.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
- /users/register
- /users/login
- /products/insertBulk // POST
- /products/[?page=1&pageSize=25&q=search]
- /products/:id
- /products/bestSeller/[?limit=10]
- /products/newest/[?limit=10]
- /orders/[?page=1&pageSize=25]
- /orders/:id
- /orders // POST - add new order
Here's an example to register a user:
const user = {
name : 'john',
family : 'doe',
email : 'john@test.com',
password:'123456',
phone:'09123456789'
}
fetch("http://localhost:3000/users/register",{
body:JSON.stringify(user),
method:'POST',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a token and user objectHere's an example to login a user:
const user = {
email : 'john@test.com',
password : '123456'
}
fetch("http://localhost:3000/users/login",{
body:JSON.stringify(user),
method:'POST',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a token and user objectHere's an example to insert mock products:
fetch("http://localhost:3000/products/insertBulk",{
method:'POST',
})
.then(response => response.json())
.then(json => console.log(json)); Here's an example to get products:
fetch("http://localhost:3000/products",{
method:'GET',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a list of productsHere's an example to get products whith params:
fetch("http://localhost:3000/products?page=1&pageSize=25&q=search",{
method:'GET',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a list of productsHere's an example to get product by id:
fetch("http://localhost:3000/products/1",{
method:'GET',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a productHere's an example to get best seller products:
fetch("http://localhost:3000/products/bestSeller?limit=10",{
method:'GET',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a list of productsHere's an example to get newest products:
fetch("http://localhost:3000/products/newest?limit=10",{
method:'GET',
})
.then(response => response.json())
.then(json => console.log(json)); // returns a list of productsHere's an example to get orders with token in header:
fetch("http://localhost:3000/orders",{
method:'GET',
headers: {
'Authorization': 'Bearer ' + token
}
})
.then(response => response.json())
.then(json => console.log(json)); // returns a list of ordersHere's an example to get order by id with token in header:
fetch("http://localhost:3000/orders/1",{
method:'GET',
headers: {
'Authorization': 'Bearer ' + token
}
})
.then(response => response.json())
.then(json => console.log(json)); // returns an order itemsHere's an example to add new order with token in header:
const order = {
orderItems : [
{
productId : 1,
quantity : 1
},
{
productId : 2,
quantity : 2
}
],
address : 'tehran',
date : '2022-27-12',
}
fetch("http://localhost:3000/orders",{
body:JSON.stringify(order),
method:'POST',
headers: {
'Authorization': 'Bearer ' + token
}
})
.then(response => response.json())
.then(json => console.log(json));