GithubHelp home page GithubHelp logo

amirkangarloo / store-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 59 KB

A simple REST API for store. This is API products includes show list of the products, sorting, filtering, search for product name and custom pagination.

License: MIT License

JavaScript 100.00%
api exprees mongodb nodejs store-api

store-api's Introduction

Store API (NodeJs - Express - MongoDB)

A simple REST API for store. This is API products includes show list of the products, sorting, filtering, search for product name and custom pagination.

Usage

first step

git clone https://github.com/amirkangarloo/store-api.git

then

cd store-api

second step

npm install

third step

Make .env file. like a below:

# === App ===
APP_URL=http://localhost:3000
APP_PORT=3000
APP_SECRET=

# === MongoDB ===
MONGO_URL=mongodb://localhost:27017
MONGO_PORT=27017
MONGO_USERNAME=
MONGO_PASSWORD=
MONGO_DB_NAME=store-api

# === Redis ===
REDIS_URL=
REDIS_PORT=
REDIS_USERNAME=
REDIS_PASSWORD=

fourth step

npm start

Route API

HTTP Method Route Result
GET api/v1/products Get a list of products

Create data

In this project, for testing router can use test data. create-data folder include 2 files.

1. products.json

This file has 23 product data.

2. import-data-into-database.js

WARNING: If using this file first delete all documents in mongo and after that, Create products data. (products.json).


usage: run command below

node .\create-data\import-data-into-database.js

Options

You can set some request header for a customized response.

Request Headers

- featured

You can set featured True or false for customized products.

example:

http://localhost:3000/api/v1/products?featured=false

- company

You can sellect company name.

example:

http://localhost:3000/api/v1/products?featured=false&company=liddy

- name

You can search on the product name. (The code logic for searching product names uses a regex and does not case sensitive.)

example:

http://localhost:3000/api/v1/products?name=Table

- sort

You can sort price, rating, created_at, name, and...

Also, you can multiple sorting.

example: sort by increase price

http://localhost:3000/api/v1/products?sort=price

example: sort by decrease price

http://localhost:3000/api/v1/products?sort=-price

example: sort by multiple

http://localhost:3000/api/v1/products?sort=price,-rating

- fields

You can select fields in response.

example:

http://localhost:3000/api/v1/products?fields=name,rating,price

- numericFilters

You can filter price and rating products.

example:

http://localhost:3000/api/v1/products?numericFilters=price>30,rating>=3

pagination

- page

You can go to another page.

example:

http://localhost:3000/api/v1/products?page=2

- limit

You can change the limit of the number of products on the list. (default = 10 )

example:

http://localhost:3000/api/v1/products?limit=5

License

MIT

store-api's People

Contributors

amirkangarloo avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.