WHile conducting a training session on ReactJs, I had to supply my students APIs for their implementation. Got so many options in Web but couldnt be satisfied. So built this one as dummy project. Hope it can help others as well.
you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)
- NodeJs
- MongoDb
- Npm
- At first clone the project.
- Run
yarn
ornpm install
to install all the dependencies - The system will run on
port: 8080
. You can modify it by changing the port inserver.js
or adding anenv
variable. - Once installed, run
yarn start
ornpm start
- The API url will be
localhost:{PORT}/{ROUTES}
fetch("{BASE_URL}/products")
.then((res) => res.json())
.then((json) => console.log(json));
fetch("{BASE_URL}/products/1")
.then((res) => res.json())
.then((json) => console.log(json));
Required Admin User account
fetch("{BASE_URL}/products", {
method: "POST",
headers: {
authorization: "bearer {TOKEN}",
},
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "BASE64",
stock: 123,
category: {
_id: "1234",
},
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
fetch("{BASE_URL}/products/category/1234")
.then((res) => res.json())
.then((json) => console.log(json));
Required Admin User account
fetch("{BASE_URL}/products/213123", {
method: "PATCH",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "BASE64",
stock: 123,
category_id: "1234",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
Required Admin User account
fetch("{BASE_URL}/products/213123", {
method: "DELETE",
})
.then((res) => res.json())
.then((json) => console.log(json));
fetch("{BASE_URL}/category")
.then((res) => res.json())
.then((json) => console.log(json));
fetch("{BASE_URL}/category/{CategoryId}")
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Account
fetch("{BASE_URL}/category", {
method: "POST",
body: JSON.stringify({
name: "test Category",
description: "Description",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Account
fetch("{BASE_URL}/category/{ID}", {
method: "PATCH",
body: JSON.stringify({
name: "test Category",
description: "Description",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Account
fetch("{BASE_URL}/category/{ID}", {
method: "DELETE",
})
.then((res) => res.json())
.then((json) => console.log(json));
Require User Authentication
fetch("{BASE_URL}/cart")
.then((res) => res.json())
.then((json) => console.log(json));
Require User Authentication
fetch('{BASE_URL}/cart',
{
method: 'POST',{
"product":{
"id": "6059fbefe439202d2bd1120a",
"quantity" : 1
},
}
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
fetch("{BASE_URL}/order")
.then((res) => res.json())
.then((json) => console.log(json));
Require Authentication
fetch("{BASE_URL}/my-order")
.then((res) => res.json())
.then((json) => console.log(json));
Require User Authentication
fetch("{BASE_URL}/order/checkout")
.then((res) => res.json())
.then((json) => console.log(json));
Require User Authentication
fetch('{BASE_URL}/order/{ID}',{
method: 'PATCH',
{
Status: any of [0,1,2]
}
})
.then((res) => res.json())
.then((json) => console.log(json));
# USER
fetch('{BASE_URL}/signup',{
method: "POST",{
email: "[email protected]",
username: 'username',
password: 'password',
firstname: 'First name',
lastname: 'Last name',
address: {
city: 'Address',
street:'Address',
number: 'Address'
zipcode: 'Address',
geolocation: {
lat: 'LAT',
long:'LONG',
},
},
phone: 'Phone Number',
}
})
.then((res) => res.json())
.then((json) => console.log(json));
fetch('{BASE_URL}/signin',{
method: "POST",{
email: "[email protected]",
password: 'password',
}
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
req.body = {
"address": {
"geolocation": {
"lat": "0",
"long": "0"
},
"city": "N/A",
"street": "N/A",
"number": 0,
"zipcode": "0"
},
"role": "user/admin",
"email": "[email protected]",
"username": "username",
"phone": "phonenumber",
"password": "password"
}
fetch('{BASE_URL}/user',{
method: "POST",req.body
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
fetch("{BASE_URL}/user/{UserId}", {
method: "DELETE",
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
req.body = {
"address": {
"geolocation": {
"lat": "0",
"long": "0"
},
"city": "N/A",
"street": "N/A",
"number": 0,
"zipcode": "0"
},
"role": "user/admin",
"email": "[email protected]",
"username": "username",
"phone": "phonenumber",
"password": "password"
}
fetch("{BASE_URL}/user/{UserId}", {
method: "PATCH",req.body
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
fetch("{BASE_URL}/user/{UserId}", {
method: "GET",
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Admin Authentication
fetch("{BASE_URL}/user/", {
method: "GET",
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Authentication
fetch("{BASE_URL}/my-detail/", {
method: "GET",
})
.then((res) => res.json())
.then((json) => console.log(json));
Require Authentication
req.body = {
"address": {
"geolocation": {
"lat": "0",
"long": "0"
},
"city": "N/A",
"street": "N/A",
"number": 0,
"zipcode": "0"
},
"role": "user/admin",
"email": "[email protected]",
"username": "username",
"phone": "phonenumber",
"password": "password"
}
fetch("{BASE_URL}/my-detail/", {
method: "PATCH",
})
.then((res) => res.json())
.then((json) => console.log(json));
- Add graphql support
- Add pagination
- Add another language support