apta-org / app-apta

A repository to provide API for APTA Services
0 stars 0 forks source link

Node/Hapi.JS/APTA Application

Build Status Code Climate Code Climate Coverage Code Style Hapi.JS Mongoose

'app-apta'

Created by: Ravi Kalli

Keywords: rest

This product uses:

Install Node

Install or Update existing node to Node.JS LTS version

Get things running

Code Overview

Dependencies

Application Structure

Authentication

Requests are authenticated using the Authorization header with a valid JWT. We use one hapijs pluggin in lib/modules/auth/index2.js that can be used to authenticate requests. The hapi-auth-jwt2 plugin using our application's secret and will return a 401 status code if the request cannot be authenticated. The payload of the JWT can then be accessed from request.auth.credentials.user in the endpoint.

HapiJS auth mecanism provide 3 Authentications mode:

Error Handling

HapiJS use Boom for errors response that use a particular format response, so we need to reformat it, to meet the Backend API specs errors handling section. So we added a preResponse server extension, to reformat it in lib/modules/api/index2.js.

Validations

Joi is used for validating request params/payload and response payload.

API Documentation

We use hapi-swagger for the API endpoints documentation. Documentation available at http://localhost:8080.

Troubleshooting