vatican

1.5.0 • Public • Published

Vatican

NPM

Vatican attemps to be a micro-framework for creating APIs as quickly as possible. One of the key features of Vatican is the use of annotations on methods to define the endpoints of the API.

For a full code example of an app using Vatican, check out this repo: https://github.com/deleteman/vatican-example

Versioning your API

By default, there is no versioning available. On the constructor, you can set the versioning strategy.

new Vatican({
    versioning: true
    })

Will enable default versioning behavior, which means it'll use the major version of each endpoint as part of the URL prefixed by a "v", i.e: /v1/your/endpoint

new Vatican({
    versioning: {
        strategy: "url",
        matching: (urlV, endpointV) {
            let v = urlV.substring(1);
            return +== +endpointV.split(".")[0];
        }
    }
    })

Using the strategy property, you can set a custom version matcher for your URLs. In the above example, it'll match URLs as /1/your/api

You can also tell Vatican to use header versioning instead of modifying your URLs

new Vatican({
    versioning: {
        strategy: "header"
    }
    })

The header used will be the "Accept" header, with the following format:

accept/vnd.vatican-version.[version number]+json

Specifying your endpoint's version compatibility

@endpoint (url: /books method:post versions:[1.2, 1.3, 1.4])

Matching function

This function is optional, if you don't provide a matching function, urls will contain the full version number you define for your endpoint (i.e /1.2.3/your/endpoint) and that number will be use to match it during the request.

Installing Vatican

$ npm install vatican

Running the tests

$ npm test

More info

Changelog

v 1.5.0

  • Added support for OPTIONS methods
  • Added endpoint versioning support
  • Added on-ready event, to avoid code referencing handler that haven't been parsed yet.
  • Added on-ready event for the database, this way, working with DB events and Vatican's events works the same way
  • Removed the need to start working with dbStart
  • Added SERVER-READY event, optional, if you want to be notified when the HTTP server is up and running

v 1.4.0

  • Added support for ES6 classes as resource handlers
  • Changed generator code to create ES6 compatible classes for resource handlers
  • Cleaned-up some code

v 1.3.2

  • Added close method on main server.
  • Fixed bug #30

v 1.3.1

  • Added new name attribute to @endpoint annotation
  • Added ability to set pre-processors on specific endpoints by name
  • Added model generator working with MongoDB
  • Auto generate handlers method's code based on their name
  • New generate syntax, allowing to specify attributes, types and http methods
  • Added index.js and package.json generator
  • Added tests to main components (Still needs more work)
  • Added removal of comments on handlers files, so now if you comment out an endpoint, it won't be parsed.
  • Improved handler parser regex
  • Improved general processing of handler file code.
  • Changed request parser to auto-parse content of PUT and POST requests into JSON (when possible)

v 1.2.4

  • Fixed bug causing incorrect parsing of post/put body content

v 1.2.3

  • Fixed bug preventing the handlers from loading installed modules using 'require'

v 1.2.2

  • Fixed bug causing problems with the pre-processing chain and the handler methods.

v 1.2.1

  • Fixed bug causing vatican to match incorrecly urls with similar templates
  • Changed preprocessing chain, so that now handler methods recieve the next function and can trigger the generic error handler functions

v 1.2.0

  • Fixed support for PUT requests
  • Added configuration overwrite on Vatican constructor and cli commands
  • Added callback function to start method of Vatican called after successful start of http server.
  • Updated cli help
  • Handlers are now stored in-memory after the first time they're loaded, so they're not loaded on every request.

v 1.1.0

  • Added pre-processor to request
  • Added post-processor to response
  • Fixed bug causing incorrect request parsing on non-post requests.

v 1.0.1

  • Changed default handler folder for create command
  • Minor readme fixes

v 1.0.0

  • Added create new project command
  • Minor fixes on readme

v 0.1.1

  • Added auto-stringify of objects passed to the send method on the response object.
  • Edited readme

v 0.0.1

  • First version

Contributing

If you feel like helping out by bug-fixing, or contributing with a new feature or whatever, just follow these simple steps:

  1. Create an issue for it.
  2. Fork the repo.
  3. Make your changes.
  4. Commit and create a pull request.
  5. Be happy :)

Contact me

If you have questions, or just want to send your love/hate, drop me an e-mail at: deleteman@gmail.com Or visit my official site at www.fernandodoglio.com

License

The MIT License (MIT)

Copyright (c) 2013 Fernando Doglio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i vatican

Weekly Downloads

1

Version

1.5.0

License

none

Unpacked Size

285 kB

Total Files

69

Last publish

Collaborators

  • deleteman