RESTful API made with Node.js where a user can list, create, update and delete products that are stored in a database. You will need a token, which will be received when you log in, so that it can handle the products.
- MongoDB
- Redis
- Node.js
- NPM / Yarn
- Clone the repository:
git clone https://github.com/kazordoon/nodejs-restful-api-hapi.git
- Get in the project directory:
cd nodejs-restful-api-hapi
- Install the dependencies:
- NPM:
npm i
| Remove the fileyarn.lock
before installing with NPM - Yarn:
yarn
- NPM:
Copy the .env.example
file to the .env
, then you will need to set the variable values into the .env
file according to your environment.
- NPM:
npm run dev
- Yarn:
yarn dev
Action | Path | Parameters | Body | Method | Returns |
---|---|---|---|---|---|
List all products | /products | -- | -- | GET | All of the products |
List one product | /products/{idProduct} | idProduct | -- | GET | The product that has the same id as the one found in the idProduct parameter |
Create a new product | /products | - | A JSON with the fields name , description and price |
POST | The created product |
Update a existing product | /products/{idProduct} | idProduct | A JSON with least one of the following fields: name , description or price |
PATCH | The updated product |
Delete a product | /products/{idProduct} | idProduct | -- | DELETE | -- |
Action | Path | Body | Method | Returns |
---|---|---|---|---|
Create a new user | /register | A JSON with the fields username and password |
POST | A JSON with a success message and a token |
Login into an account | /login | A JSON with the fields username and password |
POST | A JSON with a success message and a token |
You need to put the token on the authorization header.
- username
- Type: string
- Minimum characters: 3
- Maximum characters: 20
- password
- Type: string
- Minimum characters: 8
- Maximum characters: 50
- name:
- Type: string
- Minimum characters: 2
- Maximum characters: 50
- description
- Type: string
- Minimum characters: 20
- Maximum characters: 200
- price
- Type: number
- Minimum: 0
- Maximum: 10000
See the EXAMPLES.md.
- Node.js - JavaScript runtime environment that executes JavaScript code server-side
- MongoDB - NoSQL Database
- mongoose - MongoDB object modeling tool
- @hapi/hapi - HTTP server framework
- @hapi/boom - HTTP-friendly error objects
- @hapi/joi - Data validator for JavaScript
- bcrypt - A library to help you hash passwords
- hapi-auth-jwt2 - Authentication scheme/plugin for Hapi.js apps using JSON Web Tokens
- jsonwebtoken - An implementation of JSON Web Tokens
- ioredis - A robust, performance-focused and full-featured Redis client for Node.js
For the versions available, see the tags on this repository.
- Felipe Barros - Initial work - kazordoon
This project is licensed under the MIT License - see the LICENSE file for details