0.0.1 • Published 3 years ago

@rabelsan/nodepop-avanzado v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Install

npm install @rabelsan/nodepop-avanzado && pm2 reload ecosystem.config.js --env production

Configure environment variables

Copy .env.example to .env and review the settings.

cp .env.example .env

Load initial data

You can load the database with initial data with:

npm run init-db

Warning! this script delete database contents before the load.

Use in production only in the first deployment.

Usage

npm start

Development start

npm run dev

API Methods

Authentication

POST /api/authenticate {body: email:"example@domain.com", password: "xxxx"}

If the user credentials (email & password), are correct, it will return a valid JWT Otherwise it will return an error

HTTP/1.1 200 OK { "tokenJWT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJfaWQiOiI1ZjlkYTk4MzNlMzAyMTMzNTZkOTdlMjEiLCJpYXQiOjE2MDQ1MTU3NjIsImV4cCI6MTYwNDUxNTc2N30. YPoZWhnZxm1R3SK5Ei_xFB9_eXA073nYL-cBZfO4lrE" }

List of advertisements

GET /api/anuncios

JWT Authorization parameter required. Options:

GET /api/anuncios (body: {token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJfaWQiOiI1ZjlkYTk4MzNlMzAyMTMzNTZkOTdlMjEiLCJpYXQiOjE2MDQ1MTg2NTQsImV4cCI6MTYwNDY5MTQ1NH0. eoF7TvqS0Ray0ZOyC9T-EMuXpr0pXkAcLB3zu_fa3vk)

GET /api/aununcios (header: {key: "Authorization" value: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJfaWQiOiI1ZjlkYTk4MzNlMzAyMTMzNTZkOTdlMjEiLCJpYXQiOjE2MDQ1MTg2NTQsImV4cCI6MTYwNDY5MTQ1NH0. eoF7TvqS0Ray0ZOyC9T-EMuXpr0pXkAcLB3zu_fa3vk}

GET /api/anuncios (query string) api/authenticate?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJfaWQiOiI1ZjlkYTk4MzNlMzAyMTMzNTZkOTdlMjEiLCJpYXQiOjE2MDQ1MTg2NTQsImV4cCI6MTYwNDY5MTQ1NH0. eoF7TvqS0Ray0ZOyC9T-EMuXpr0pXkAcLB3zu_fa3vk

HTTP/1.1 200 OK [ { "sale": true, "tags": "bicicletas", "bycicles", "trek", "madone" , "_id": "5f5a6ae91be10bf7d4a1956a", "name": "Trek Madone SLR7", "price": 5800, "photo": "images/bike-trek-madone-SLR7.jpg" } ]

HTTP/1.1 401 Unauthorized { "error": "no token provided" }

HTTP/1.1 401 Unauthorized { "error": "jwt expired" }

Example filters:

Retrieves one advertisement

GET /api/anuncios/_id

{ "result": { "sale": false, "tags": "guantes", "globes", "bicicleta", "bycicle" , "_id": "5f5a6ae91be10bf7d4a1956b", "name": "Guantes Bluegrass Manatee", "price": 12, "photo": "images/guantes-bluegrass-manatee.jpg", "__v": 0 }

Create advertisement

POST /api/anuncios/upload file: {'photo=../casco-Dexter-Proton-Negan.jpg'} body: { name: 'casco-Dexter-Proton-Negan', sale: 'true', price: '60', tags: 'casco', 'moto' }

{ "result": { "sale": true, "tags": "casco", "moto" , "_id": "5f5b9b0df9d13e2d0907582c", "name": "casco-Dexter-Proton-Negan", "price": 60, "photo": "images/ad_27942a04-233f-428a-905a-a793d2c847d3_casco-Dexter-Proton-Negan.jpg", "__v": 0 } }

Update advertisement

PUT /api/anuncios/<_id> body: { name: "Casco NEGRO Dexter Proton Negan" }

{ "result": { "sale": true, "tags": "casco", "moto" , "_id": "5f5b9b0df9d13e2d0907582c", "name": "Casco NEGRO Dexter Proton Negan", "price": 60, "photo": "images/ad_27942a04-233f-428a-905a-a793d2c847d3_casco-Dexter-Proton-Negan.jpg", "__v": 0 } }

Delete advertisement

DELETE /api/anuncios/<_id>

Returns: HTTPCode 200

How to start a local mongodb instance for development

./bin/mongod --dbpath ./data/db --directoryperdb

APIDOC (Requires to start the application first)

Author

👤 Ramón Beltrán

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator