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")