gothinkster/hapijs-realworld-example-app

Name: hapijs-realworld-example-app

Owner: Thinkster

Description: Real World Hapi.JS + Mongoose backend implementations

Created: 2017-10-02 18:26:43.0

Updated: 2018-05-23 12:32:26.0

Pushed: 2018-05-13 22:29:52.0

Homepage: https://realworld.io

Size: 211

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Node/Hapi.JS/Mongoose Example App

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

Example Hapi.JS (Hapi.JS + Mongoose) codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.

Getting started

Install Node

Install Node.JS LTS version

To get the Node server running locally
To get the Node server running locally with Docker

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/index.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/index.js.

Validations

We use Joi for validating request params/payload and response payload.

Documentation

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

Contributing

PRs and issues are welcome!

remote rename origin upstream
remote add origin {YOUR_URL}

Credits

The mongoose models come from the node-express-realworld-example-app codebase.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.