Fake Store REST API
Fake Store based on the "Fake Store API"
Explore the docs »
Report Bug
Request Feature
Table of Contents
About The Project
I built this API because i was not satisfied with other other api's found on the internet due to the limitations. I needed to be able to create, update and remove records from database. !!!WARNING!!! As it's still work in progress!
Demo
At the moment you can add new products, update and delete those but you need to be authorized. Just head to the login page. Login: testuser Password: fakestore You can use as you like but don't overstay your welcome :) Demo
Built With
Getting Started
To get a local copy up and running follow these simple example steps.
Usage
Don't forget to create and activate virtual environment. If you want to deploy it on your server you need to do the following steps:
- download or clone this repo:
- Clone with SSH:
git@github.com:Gogee90/Fake-Store-REST-API.git
- Clone with HTTPS
https://github.com/Gogee90/Fake-Store-REST-API.git
- Install requirements:
If you're on linux:
pip3 install -r requirements.txt
On windows:pip install -r requirements.txt
- Then:
python manage.py migrate
python manage.py createsuperuser your_username
To get things up and running:
python manage.py runserver
Now get to the interesting part.
It's up to you what you're going to use to manipulate data. I used axios and i'm 100% sure you can use fetch if you feel more comfortable with it.
- To get all products
https://gogee90.pythonanywhere.com/api/products/
- To get a single product for example:
https://gogee90.pythonanywhere.com/api/products/47
- All product categories:
https://gogee90.pythonanywhere.com/api/category/
- A single product category:
https://gogee90.pythonanywhere.com/api/category/1
- Get comments to the corresponding products:
https://gogee90.pythonanywhere.com/api/comments/15
- Get a list of users and products added by them:
https://gogee90.pythonanywhere.com/api/users/
- Get a single user:
https://gogee90.pythonanywhere.com/api/users/2
- Get all carts:
https://gogee90.pythonanywhere.com/api/carts/
- Get a single cart:
https://gogee90.pythonanywhere.com/api/carts/single/1
- Get all carts added by user:
https://gogee90.pythonanywhere.com/api/carts/1
- In order to perform actions on the database you need to be authorized:
https://gogee90.pythonanywhere.com/api/'dj-rest-auth/login
To login you need to provide username and password, the response will return a token. You can store it in, for instance, in the localStorage. Use that token to use methods PUT, DELETE and POST.
The example of usage.
- To perform a simple GET request:
axios.get(`https://gogee90.pythonanywhere.com/api/products/47`)
.then(response => {
console.log(response)
})
- To perform a POST request:
#To upload an image you need to use FormData();
let formData = new FormData()
formData.append('category', category)
formData.append('description', description)
formData.append('id', product_id)
formData.append('image', image)
formData.append('price', price)
formData.append('title', title)
axios.post('https://gogee90.pythonanywhere.com/api/products/', formData, {
headers: {
'Authorization': 'Token your_token',
},
}).then((response) => {
console.log(response)
}).catch(err => {
console.log(err)
})
- To perform a PUT request:
let formData = new FormData()
formData.append('category', category)
formData.append('description', description)
formData.append('id', product_id)
formData.append('image', image)
formData.append('price', price)
formData.append('title', title)
axios.put(`https://gogee90.pythonanywhere.com/api/products/47`,formData, {
headers: {
'Authorization': 'Token your_token',
},
}).then((response) => {
console.log(response)
}).catch(err => {
console.log(err)
})
- To perform a DELETE:
axios({
method: 'delete',
url: `https://gogee90.pythonanywhere.com/api/products/47`,
headers: {
'Authorization': `Token your_token`
},
}).then(response => {
console.log(response)
})
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Igor Nikolaev - linkedin-url - gogee09@gmail.com
Project Link: https://github.com/Gogee90/Fake-Store-REST-API/blob/master/README.md