- 📖 About the Project
- 💻 Getting Started
- 👥 Authors
- 🔭 Future Features
- 🤝 Contributing
- ⭐️ Show your support
- 🙏 Acknowledgements
- 📝 License
[E X APi] is the backend application for the ECommerce website where the user can add the products update and delete a products. If the user like the product he/she can add to cart it show much qunatity they need. The user login and log out by the Token base Authentication.
- [User Registration and Authentication]
- [When the user adds a product to the cart with a certain quantity, the quantity of the product also decreases.]
- [Add Active Storage to store the image of the product.]
There are 4 main resources need in ECommerence prototypes:
- Products http://127.0.0.1:3001/api/v1/products
- Carts http://127.0.0.1:3001/api/v1/carts
- Users http://127.0.0.1:3001/api/v1/users
- Login Token http://127.0.0.1:3001/api/v1/login
## How to
you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)
fetch("http://127.0.0.1:3001/api/v1/products")
.then((res) => res.json())
.then((json) => console.log(json));
fetch("http://127.0.0.1:3001/api/v1/products/1")
.then((res) => res.json())
.then((json) => console.log(json));
fetch("http://127.0.0.1:3001/api/v1/products", {
method: "POST",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "test Description",
image: "Add a File",
category: "electronic",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
/* will return
{
id:31,
title:'...',
price:'...',
category:'...',
description:'...',
image:'...'
quantity: '....'
}
*/
Note: Posted data will not really insert into the database and just return a fake id.
fetch("http://127.0.0.1:3001/api/v1/products/7", {
method: "PUT",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "File",
category: "electronic",
quantity: '12'
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
/* will return
{
id:7,
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
quantity: '12'
}
*/
```js
fetch("http://127.0.0.1:3001/api/v1/products/8", {
method: "DELETE",
});
Nothing will delete on the database.
fields:
{
id:Number,
title:String,
price:Number,
category:String,
description:String,
image:file
quantity: String
}
GET:
- /products (get all products)
- /products/1 (get specific product based on id)
- /products (Creating a Product)
- /products/1 (Deleting a Products)
- /products/1 (Updating a Products)
fetch("http://127.0.0.1:3001/api/v1/carts", {
method: "PUT",
body: JSON.stringify({
total_price: 56
quantity: '12'
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
/* will return
{
id:1,
total_price: 56
quantity: '12'
created_at: date
update_at: date
}
*/
GET:
- /carts
- /carts/1
// Cart display only the user cart which user selected
POST:
- /carts
PATCH:
- /carts/1
DELETE:
- /carts/1
fetch("http://127.0.0.1:3001/api/v1/user", {
method: "POST",
body: JSON.stringify({
name: 'test',
email: 'test@example.com',
passoword: 'Test1122'
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
/* will return
{
id:1,
name: 'test',
email: 'test@example.com',
passoword: 'Test1122'
}
*/
/me
fields:
{
email:String,
password:String
}
POST:
- /login
To get a local copy up and running, follow these steps.
In order to run this project you need:
- git
use the following link to setup
git
if you dont have it already installed on your computer
- Ruby
use the following link to setup
Ruby
if you dont have it already installed on your computer
- Rails
use the following link to setup
Rails
if you dont have it already installed on your computer
- PostgreSQL
use the following link to setup
PostgreSQL
if you dont have it already installed on your computer
Clone this repository to your desired folder:
git clone https://github.com/Hassaanjbaig-code/E_X-Backend.git
Install dependencies:
cd E_X-Backend
bundle install
Edit config/database.yml
with your database connection info. Run the foolowing command
rails db:create
rails db:schema:load
The following command can be used to run the application.
rails s
👤 Hassaan Baig
- GitHub: @Hassaan Baig
- LinkedIn: Hassaan Baig
- [Add Admin dashboard]
- [Add payment system]
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
If you like this project, please don't forget to follow the contributors and give it a star.
This project is MIT licensed.