Skip to content

Commit

Permalink
Merge branch 'dotenv' of https://github.com/ld-web/fake-store-api int…
Browse files Browse the repository at this point in the history
…o ld-web-dotenv
  • Loading branch information
keikaavousi committed Mar 9, 2022
2 parents f8ec9a2 + 0f675ef commit 754effb
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 6,345 deletions.
Binary file removed .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PORT=8765

DB_HOST=localhost
DB_USERNAME=root
DB_PASSWORD=example
DB_NAME=fake_store
DB_PORT=27017
DATABASE_URL=mongodb://$DB_USERNAME:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME?authSource=admin
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
node_modules
package-lock.json
.vscode
app.js
Procfile
node_modules/
Procfile
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 MohammadReza Keikavousi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
155 changes: 84 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
# FakeStoreAPI

[FakeStoreAPI](https://fakestoreapi.com) is a free online REST API that you can use whenever you need Pseudo-real data for
your e-commerce or shopping website without running any server-side code.
It's awesome for teaching purposes, sample codes, tests and etc.
your e-commerce or shopping website without running any server-side code.
It's awesome for teaching purposes, sample codes, tests and etc.

You can visit in detail docs in [FakeStoreAPI](https://fakestoreapi.com) for more information.

## Why?

When I wanted to design a shopping website prototype and needed fake data, I had to
use lorem ipsum data or create a JSON file from the base. I didn't find any online free web service
to return semi-real shop data instead of lorem ipsum data.
so I decided to create this simple web service whit NodeJs(express) and MongoDB as a database.
so I decided to create this simple web service with NodeJs(express) and MongoDB as a database.

## Resources

There are 4 main resources need in shopping prototypes:

### new! Login with token has been added to FakeStoreApi!
- Products https://fakestoreapi.com/products
- Carts https://fakestoreapi.com/carts
- Users https://fakestoreapi.com/users
- Login Token https://fakestoreapi.com/auth/login

### New! "Rating" (includes rate and count) has been added to each product object!

## How to

you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)

### Get all products

```js
fetch('https://fakestoreapi.com/products')
.then(res => res.json())
.then(json => console.log(json))
fetch("https://fakestoreapi.com/products")
.then((res) => res.json())
.then((json) => console.log(json));
```

### Get a single product

```js
fetch('https://fakestoreapi.com/products/1')
.then(res => res.json())
.then(json => console.log(json))
fetch("https://fakestoreapi.com/products/1")
.then((res) => res.json())
.then((json) => console.log(json));
```

### Add new product

```js
fetch('https://fakestoreapi.com/products', {
method: 'POST',
fetch("https://fakestoreapi.com/products", {
method: "POST",
body: JSON.stringify({
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
})
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then(res => res.json())
.then(json => console.log(json))
.then((res) => res.json())
.then((json) => console.log(json));

/* will return
{
Expand All @@ -74,18 +77,18 @@ Note: Posted data will not really insert into the database and just return a fak
### Updating a product

```js
fetch('https://fakestoreapi.com/products/7', {
method: 'PUT',
fetch("https://fakestoreapi.com/products/7", {
method: "PUT",
body: JSON.stringify({
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
})
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then(res => res.json())
.then(json => console.log(json))
.then((res) => res.json())
.then((json) => console.log(json));

/* will return
{
Expand All @@ -100,18 +103,18 @@ fetch('https://fakestoreapi.com/products/7', {
```

```js
fetch('https://fakestoreapi.com/products/8', {
method: 'PATCH',
fetch("https://fakestoreapi.com/products/8", {
method: "PATCH",
body: JSON.stringify({
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
})
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then(res => res.json())
.then(json => console.log(json))
.then((res) => res.json())
.then((json) => console.log(json));

/* will return
{
Expand All @@ -130,9 +133,9 @@ Note: Edited data will not really be updated into the database.
### Deleting a product

```js
fetch('https://fakestoreapi.com/products/8', {
method: 'DELETE'
})
fetch("https://fakestoreapi.com/products/8", {
method: "DELETE",
});
```

Nothing will delete on the database.
Expand All @@ -143,16 +146,17 @@ You can use query string to limit results or sort by asc|desc

```js
// Will return all the posts that belong to the first user
fetch('https://fakestoreapi.com/products?limit=3&sort=desc')
.then(res => res.json())
.then(json => console.log(json))
fetch("https://fakestoreapi.com/products?limit=3&sort=desc")
.then((res) => res.json())
.then((json) => console.log(json));
```

## All available routes

### Products

```js
fields:
fields:
{
id:Number,
title:String,
Expand All @@ -164,29 +168,31 @@ fields:
```

GET:

- /products (get all products)
- /products/1 (get specific product based on id)
- /products/1 (get specific product based on id)
- /products?limit=5 (limit return results )
- /products?sort=desc (asc|desc get products in ascending or descending orders (default to asc))
- /products/products/categories (get all categories)
- /products/category/jewelery (get all products in specific category)
- /products?sort=desc (asc|desc get products in ascending or descending orders (default to asc))
- /products/products/categories (get all categories)
- /products/category/jewelery (get all products in specific category)
- /products/category/jewelery?sort=desc (asc|desc get products in ascending or descending orders (default to asc))

POST:
- /products

-PUT,PATCH
- /products/1
- /products

-DELETE
- /products/1
-PUT,PATCH

- /products/1

-DELETE

- /products/1

### Carts

```js
fields:
fields:
{
id:Number,
userId:Number,
Expand All @@ -196,29 +202,31 @@ fields:
```

GET:

- /carts (get all carts)
- /carts/1 (get specific cart based on id)
- /carts/1 (get specific cart based on id)
- /carts?startdate=2020-10-03&enddate=2020-12-12 (get carts in date range)
- /carts/user/1 (get a user cart)
- /carts/user/1?startdate=2020-10-03&enddate=2020-12-12 (get user carts in date range)
- /carts?limit=5 (limit return results )
- /carts?sort=desc (asc|desc get carts in ascending or descending orders (default to asc))

POST:
- /carts

PUT,PATCH:
- /carts/1
- /carts

DELETE:
- /carts/1
PUT,PATCH:

- /carts/1

DELETE:

- /carts/1

### Users

```js
fields:
fields:
{
id:20,
email:String,
Expand All @@ -241,34 +249,39 @@ fields:
phone:String
}
```

GET:

- /users (get all users)
- /users/1 (get specific user based on id)
- /users/1 (get specific user based on id)
- /users?limit=5 (limit return results )
- /users?sort=desc (asc|desc get users in ascending or descending orders (default to asc))

POST:
- /users

- /users

PUT,PATCH:
- /users/1

- /users/1

DELETE:
- /users/1


- /users/1

### Auth

```js
fields:
fields:
{
username:String,
password:String
}
```

POST:
- /auth/login

- /auth/login

## ToDo

Expand Down
Loading

1 comment on commit 754effb

@rahmanrusmana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thfhf

Please sign in to comment.