restwell

0.4.1 • Public • Published

restwell

A personal & basic express.js & mongoose REST API resource generator (routes, handlers, mongoose schema skeleton, integration tests)

Because it uses async functions, the generated code will only work for node.js version >= 8

Build Status npm David JavaScript Style Guide

Quick start

  • install restwell
    npm install <-g> <--save-dev> restwell

  • generate a REST API resource
    restwell generate resource
    Then answer to the questions :).

It will generate the following files:

|resources
  |
  |-util
    |
    |-find-object.js // A simple function to the a doc by its id
    |-safe-async.js // Wrapper to catch error for async/await middleware
    |-paginate.js // Pagination middlewre
  | <name>
    |
    |-model.js // Juste a simple mongoose skeleton (use the --no-model option to not generate this file. Please note that the handlers & everything will integrate the mongoose API anyway.)
    |-routes.js // All the resource's routes (get, post, put patch, delete)
    |-handlers.js // All the ressource's route handlers (express route middlewares):
    |-index.js // Entry point for your resource (basically, it exports the routes file)
  |-test
    |-<name>.handlers.test.js // API enpoints integration test skeleton

if you have installed restwell locally (which is a good idea!), you may want to add an new line to the scripts part in the package.json file.

"scripts": {
  "restwell": "restwell"
}

Then you will be able to run the restwell script like this:
npm run restwell generate resource

Available options

     -h, --help         Display help                                      
     -V, --version      Display version                                   
     --no-color         Disable colors                                    
     --quiet            Quiet mode - only displays warn and error messages
     -v, --verbose      Verbose mode - will also output debug messages

Test

run npm run test

Contribution

As this package is really new, all PR, issues and feedbacks are more than welcome!

Credits

  • the expressjs generator, which was a great source of inspiration to see how to start.
  • Handlebars.js, build semantic templates effectively with no frustration.
  • Caporal.js, a full-featured framework for building command line applications (cli) with node.js.
  • Inquirer.js, A collection of common interactive command line user interfaces.

Package Sidebar

Install

npm i restwell

Weekly Downloads

1

Version

0.4.1

License

GPL-3.0

Last publish

Collaborators

  • laudeon