Giter Club home page Giter Club logo

node-wishlist-rest-api's Introduction

NODE WISHLIST REST API

Description

This is a REST API to register users and their favorite products.

Stacks/Dependencies

This app uses Docker to build and Postgres Database image.

  • docker
  • postgres
  • jest
  • yarn v1.22.5
  • node v15.14.0

Installing dependencies/Configurations

In the root directory of the app, run this command:

yarn install

or just:

yarn

then run commands to start docker and configure database:

To start docker database images run:

yarn docker:up 

and then run migrations:

yarn migrate

so dev environment is ready to start!

Running app

In the root project run:

yarn start

This command run server in localhost on the port 3000.

Testing code

To run tests run the following commands:

yarn docker:test:up

this command updates docker instance with database for tests

and this command create test database:

yarn db:create:test

and to run migrations:

yarn migrate:test

and finally run:

yarn test

to start testing!

Also if you want to se app coverage, run:

yarn test:c

PS: this test generate a directory named coverage on the root of the project. You can check a more detailed status of the code coverage on coverave/lcov-report/index.html.

After that you can simply run yarn start or yarn test, so you don't need to re-run config commands again.

Endpoints

GET /api/users
GET /api/users/<id>
POST /api/users
PUT /api/users/<id>
DELETE /api/users/<id>

GET /api/products
GET /api/products/<id>
POST /api/products

POST /api/auth/login

USERS

GET /api/users

return all users, needs authentication. headers: { 'x-access-token': }

GET /api/users/

return user by id, needs authentication. headers: { 'x-access-token': }

POST /api/users

create new user, don't need authentication. body: { name: required, email: required, password: required }

PUT /api/users/

update user, have to be authentication. headers: { 'x-access-token': } body: { name: required, email: required, password: required }

DELETE /api/users/

delete user by id, have to be authentication. headers: { 'x-access-token': }

PRODUCTS

GET /api/products

get all products, needs authentication. headers: { 'x-access-token': } query: { page: }

example: /api/products?page=1

GET /api/products/

get product by id, needs authentication. headers: { 'x-access-token': }

POST /api/products

favorite product, needs authentication. headers: { 'x-access-token': } body: { userId: required, sku: required, }

AUTH

POST /api/auth/login

return access token to include on private endpoints, don't need authentication. body: { email: required, password: required }

Usage

First of all create a user on route POST /api/users so you can authenticate using the email and password on POST /api/auth/login. After this, you should get product list on GET /api/products and get the id of this product, then on the POST /api/products you should pass your userId and the id of the product as a sku code to favorite this product.

Code Architecture

It contains code architecture commonly used by the community, with some modifications:

  • src/app : app module containing the API.
    • controllers: controller module containing all controllers
    • middlewares: middlewares module that includes auth middleware.
    • models: models module containing sequelize modules and init models.
    • policies: this module includes favorite product logic (business rules).
    • repository: module layer that comunicates with database.
    • routes: module to register all app routes.
    • services: module layer that contains API calls.
    • utils: module that contains helpers/validations, etc.
  • src/config : here are centralized the API config, database, etc.
  • src/database : module that start database and store migrations.

StyleGuide

This project uses AirBnb StyleGuide with some modifications in the rules:

...,
rules: {
    'arrow-parens': ['error', 'as-needed'],
},
...

node-wishlist-rest-api's People

Watchers

James Cloos avatar Gabriel De Marco 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.