Thanks to visit codestin.com
Credit goes to github.com

Skip to content

andrews-felipe/museum-api

Repository files navigation

Docs Museum API v0.0.0

Auth

Authenticate

POST /auth

Headers

Name Type Description
Authorization String

Basic authorization with email and password.

Parameters

Name Type Description
access_token String

Master access_token.

Beacon

Create beacon

POST /beacons

Parameters

Name Type Description
access_token String

admin access token.

name

Beacon's name.

description

Beacon's description.

Delete beacon

DELETE /beacons/:id

Parameters

Name Type Description
access_token String

admin access token.

Retrieve beacon

GET /beacons/:id

Parameters

Name Type Description
access_token String

admin access token.

Retrieve beacons

GET /beacons

Parameters

Name Type Description
access_token String

admin access token.

q String optional

Query to search.

page Number optional

Page number.

limit Number optional

Amount of returned items.

sort String[] optional

Order of returned items.

fields String[] optional

Fields to be returned.

Update beacon

PUT /beacons/:id

Parameters

Name Type Description
access_token String

admin access token.

name

Beacon's name.

description

Beacon's description.

User

Create user

POST /users

Parameters

Name Type Description
access_token String

Master access_token.

email String

User's email.

password String

User's password.

name String optional

User's name.

picture String optional

User's picture.

role String optional

User's role.

Delete user

DELETE /users/:id

Parameters

Name Type Description
access_token String

User access_token.

Retrieve current user

GET /users/me

Parameters

Name Type Description
access_token String

User access_token.

Retrieve user

GET /users/:id

Retrieve users

GET /users

Parameters

Name Type Description
access_token String

User access_token.

q String optional

Query to search.

page Number optional

Page number.

limit Number optional

Amount of returned items.

sort String[] optional

Order of returned items.

fields String[] optional

Fields to be returned.

Update password

PUT /users/:id/password

Headers

Name Type Description
Authorization String

Basic authorization with email and password.

Parameters

Name Type Description
password String

User's new password.

Update user

PUT /users/:id

Parameters

Name Type Description
access_token String

User access_token.

name String optional

User's name.

picture String optional

User's picture.

Visitant

Create visitant

POST /visitantes

Parameters

Name Type Description
access_token String

user access token.

dateTimeAcess

Visitant's dateTimeAcess.

name

Visitant's name.

email

Visitant's email.

phone

Visitant's phone.

id_device

Visitant's id_device.

Retrieve visitant

GET /visitantes/:id

Parameters

Name Type Description
access_token String

user access token.

Retrieve visitants

GET /visitantes

Parameters

Name Type Description
access_token String

user access token.

q String optional

Query to search.

page Number optional

Page number.

limit Number optional

Amount of returned items.

sort String[] optional

Order of returned items.

fields String[] optional

Fields to be returned.

Update visitant

PUT /visitantes/:id

Parameters

Name Type Description
access_token String

user access token.

dateTimeAcess

Visitant's dateTimeAcess.

name

Visitant's name.

email

Visitant's email.

phone

Visitant's phone.

id_device

Visitant's id_device.

Commands

After you generate your project, these commands are available in package.json.

npm test # test using Jest
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run dev # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs

Playing locally

First, you will need to install and run MongoDB in another terminal instance.

$ mongod

Then, run the server in development mode.

$ npm run dev
Express server listening on http://0.0.0.0:9000, in development mode

If you choose to generate the authentication API, you can start to play with it.

Note that creating and authenticating users needs a master key (which is defined in the .env file)

Deploy

Here is an example on how to deploy to Heroku using Heroku CLI:

# start a new local git repository
git init

# create a new heroku app
heroku apps:create my-new-app

# add heroku remote reference to the local repository
heroku git:remote --app my-new-app

# add the MongoLab addon to the heroku app
heroku addons:create mongolab

# set the environment variables to the heroku app (see the .env file in root directory)
heroku config:set MASTER_KEY=masterKey JWT_SECRET=jwtSecret

# commit and push the files
git add -A
git commit -m "Initial commit"
git push heroku master

# open the deployed app in the browser
heroku open

The second time you deploy, you just need to:

git add -A
git commit -m "Update code"
git push heroku master

Directory structure

Overview

You can customize the src and api directories.

src/
├─ api/
│  ├─ user/
│  │  ├─ controller.js
│  │  ├─ index.js
│  │  ├─ index.test.js
│  │  ├─ model.js
│  │  └─ model.test.js
│  └─ index.js
├─ services/
│  ├─ express/
│  ├─ facebook/
│  ├─ mongoose/
│  ├─ passport/
│  ├─ sendgrid/
│  └─ your-service/
├─ app.js
├─ config.js
└─ index.js

src/api/

Here is where the API endpoints are defined. Each API has its own folder.

src/api/some-endpoint/model.js

It defines the Mongoose schema and model for the API endpoint. Any changes to the data model should be done here.

src/api/some-endpoint/controller.js

This is the API controller file. It defines the main router middlewares which use the API model.

src/api/some-endpoint/index.js

This is the entry file of the API. It defines the routes using, along other middlewares (like session, validation etc.), the middlewares defined in the some-endpoint.controller.js file.

services/

Here you can put helpers, libraries and other types of modules which you want to use in your APIs.

About

Web service gerado com yeoman rest-generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published