Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@vissenta/rest-hapi

JKHeadley12MIT2.2.1

A RESTful API generator for hapi

hapi, API, RESTful, mongoose, generator

readme

rest-hapi logo


rest-hapi title

A RESTful API generator rest-hapi tweet

rest-hapi is a hapi plugin that generates RESTful API endpoints based on mongoose schemas. It provides a powerful combination of relational structure with NoSQL flexibility. You define your data models and the rest is done for you. Have your API up and running in minutes!

Features


rest-hapi is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial!

GitAds


Live demo

rest-hapi-demo-optimized

View the swagger docs for the live demo:

https://demo.resthapi.com

Or, for a more complete example, check out the appy api:

https://api.appyapp.io

Documentation

Check out the docs on the official site!

Requirements

You need Node.js installed and you'll need MongoDB installed and running.

Quick Start

rest-hapi-demo-alt-optimized

(NOTE: For an alternative quick start, check out his awesome yeoman generator for rest-hapi.)

1) Clone the demo repo

$ git clone https://github.com/JKHeadley/rest-hapi-demo.git
$ cd rest-hapi-demo

2) Install the dependencies

$ npm install

3) Seed the models

$ ./node_modules/.bin/rest-hapi-cli seed

4) Start the server

$ npm start

5) View the API docs at

http://localhost:8080/

...have fun!

Example Projects

appy: A boilerplate web app.

rest-hapi-demo: A simple demo project implementing rest-hapi in a hapi server.

Contributing

We welcome contributions to rest-hapi! These are the many ways you can help:

Please read our contribution guide to get started. Also note that this project is released with a Contributor Code of Conduct, please make sure to review and follow it.

Contributors

Thanks goes to each one of our contributors! 🙏

Become a contributor.

Backers

Support us with a monthly donation and help us continue our activities! Become a backer.

Questions?

If you have any questions/issues/feature requests, please feel free to open an issue. We'd love to hear from you!

Support

Like this project? Please star it!

License

rest-hapi is licensed under a MIT License.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

2.2.0 - 2020-07-08

Added

Fixed

2.1.0 - 2020-04-11

Added

Fixed

2.0.0 - 2020-03-24 BREAKING

Please see the release notes.

1.9.0 - 2019-09-22 BREAKING

Changed

1.8.0 - 2019-09-21

Changed

1.7.0 - 2019-09-13

Added

1.6.0 - 2019-05-06

Added

Fixed

1.5.0 - 2019-04-30

Added

Changed

1.4.0 - 2019-03-18

Added

Changed

Fixed

1.3.0 - 2018-06-14

Added

  • Added 'swaggerHost' config option.

Changed

  • Removed bcrypt dependency

Fixed

  • Attempt to fix windows error

1.2.0 - 2018-05-31

Changed

  • Updated dependencies to fix security vulnerability.
  • Refactored logging to be more consistent.

1.0.0 - 2018-05-27 BREAKING

Please see the release notes.

0.43.0 - 2018-03-23

Changed

  • Updated auditLog to get correct IP when behind a reverse proxy such as nginx.

0.42.0 - 2018-03-22

Added

  • Added option to toggle swagger protocol (http or https) with config.enableSwaggerHttps.

0.41.0 - 2018-03-17

Added

  • config.enableSwaggerUI to config.js to determine wether SwaggerUI will be generated or no.

0.40.0 - 2018-01-11

Added

0.39.0 - 2017-12-22 BREAKING

Added

  • Added "remove: pre" middleware.

Changed

  • BREAKING Swapped parameters for "add: pre" middleware for consistency.
Before After
add
pre(request, payload, Log) pre(payload, request, Log)

0.38.0 - 2017-12-12

Added

Changed

  • Added ipAddress and notes to auditLog model
  • Fixed date to set to actual current date in auditLog model
  • Removed required fields in auditLog model
  • updated errorHandler.formatResponse to handle boom errors and normal errors

0.37.0 - 2017-11-17

Added

Fixed

  • Moved testHelper to utilities directory to be included in npm module.
  • Moved query-string to regular dependencies for testHelper.
  • Updated travis since it broke for no apparent reason.
  • Fixed bug preventing associations added from wrapper methods to update correctly.

0.36.0 - 2017-11-11

Added

  • Exposed testHelper to RestHapi object, mostly for server injection utilities.

Fixed

  • Fixed bug preventing _id filtering for getAll queries with real ObjectIds.

0.35.0 - 2017-11-10

Added

  • Updated joi model for object types.

Fixed

  • Fixed bug preventing object types.

0.34.0 - 2017-11-05

Added

  • Added error response for db conflicts.

Fixed

  • Auditlog validation warning.
  • Fix payload copies to work with ObjectIds.
  • Added missing permissions.
  • Added missing params to mongoose wrappers.

0.33.0 - 2017-10-23

Added

  • Endpoint activity history tracking via Audit Logs

0.32.0 - 2017-10-23 BREAKING

Changed

  • BREAKING Modified update: pre middleware to include payload copy. This is more consistent and allows the original payload to remain unchanged.
    • The table below shows the middleware functions before (v0.31.1) and after (v0.32.0)
Before After
update
pre(_id, request, Log) pre(_id, payload, request, Log)

0.31.0 - 2017-10-19

Added

  • Added end to end unit tests.

Changed

  • Updated list and find to return original "_id"s instead of strings.
  • Swapped to js Promise rather than Q promise for mongoose.

Fixed

  • Fixed bug preventing "$where" association queries.
  • Added a 'select' call to association endpoints to allow owner object to be updated during association middleware.
  • Fixed bug with linking model modelName.
  • Added missing return statement to removeAssociation. Was causing promises to return before mongo entries updated.

0.30.0 - 2017-10-12

Added

0.29.0 - 2017-10-10

Added

Changed

  • Deprecated routeOptions.scope and routeOptions.scope.scope and replaced with routeOptions.routeScope and routeOptions.routeScope.rootScope.

0.28.0 - 2017-09-29

Added

Fixed

  • Updated hapi-swagger to fix circular reference issue.

0.27.0 - 2017-09-28 BREAKING

Added

  • Added option (config.embedAssociations) to use linking model collections.
    • See docs for details.

Changed

  • BREAKING config.embedAssociations set to false by default to take advantage of mongoose virtuals. If you already have documents in your db, set this option to true to continue with the same functionality.
    • If possible, future versions will include a cli command to convert existing db data between MANY_MANY structures.

0.26.0 - 2017-09-24

Added

  • Added config option to disable 500 response for response validation (disabled by default).

Changed

  • Cleaned up tests
  • Major updates to joi helper functions including support for nested fields.

0.25.0 - 2017-09-20

Added

  • Added config option to enable logging of routes and scopes (disabled by default).

0.24.0 - 2017-09-19

Added

  • Exposed joi helper methods, including the rest-hapi version of Joi ObjectId.

    Fixed

  • Throw error when payload is empty for addMany.

0.23.0 - 2017-09-12

Added

  • Allow custom errors in middleware

Changed

  • Cleaned up tests
  • Removed requirement that middlware functions return a promise.

0.22.0 - 2017-09-08

Added

  • getAll association middleware
  • Uncommented and updated deleteOne handler tests.

Changed

  • Replaced Boom.serverTimeout with .badImplementation

0.21.0 - 2017-09-06

Added

  • list and find pre middleware
  • Uncommented and updated create and update handler tests.

0.20.3 - 2017-09-01

Changed

  • Fixed bug that missed when a payload is an array of Ids.

0.20.2 - 2017-08-31

Added

  • Uncommented and updated find handler tests.

Changed

  • Update dependencies and tests so that rest-hapi works under node v8.

0.20.0 - 2017-08-29 BREAKING

Added

  • Hapi request object now accessible in middleware functions.

Changed

  • BREAKING Middleware function parameters have changed to support the request object.
    • The table below shows the middleware functions before (v0.19.2) and after (v0.20.0)
Before After
list
post(query, result, Log) post(request, result, Log)
--- ---
find
post(query, result, Log) post(request, result, Log)
--- ---
create
pre(payload, Log) pre(payload, request, Log)
post(document, result, Log) post(document, request, result, Log)
--- ---
update
pre(_id, payload, Log) pre(_id, request, Log)
post(payload, result, Log) post(request, result, Log)
--- ---
delete
pre(_id, hardDelete, Log) pre(_id, hardDelete, request, Log)
post(hardDelete, deleted, Log) post(hardDelete, deleted, request, Log)