hapi-align-json

4.0.0 • Public • Published

hapi-align-json Build status for hapi Align JSON

Respond with beautiful JSON

Why?

  • Quick alternative to HTML in some cases.
  • Optimize your API for readability.
  • Has the best formatting.

Install

npm install hapi-align-json

Usage

Register the plugin on your server to enable beautiful JSON responses.

const hapi = require('@hapi/hapi');
const alignJson = require('hapi-align-json');
 
const server = hapi.server();
 
const init = async () => {
    await server.register(alignJson);
    server.route({
        method : 'GET',
        path   : '/',
        handler() {
            return { foo : 'bar', ping : 'pong', wee : { hi : 'bye',  tea : 'time' }, knick : 'knack', back : 'pack' };
        }
    });
    await server.start();
    console.log('Server ready:', server.info.uri);
};
 
init();

Visiting the above route will return a JSON response with highly readable formatting because of this plugin.

{
    "foo"  : "bar",
    "ping" : "pong",
    "wee"  : {
        "hi"  : "bye",
        "tea" : "time"
    },
    "knick" : "knack",
    "back"  : "pack"
}

Contributing

See our contributing guidelines for more details.

  1. Fork it.
  2. Make a feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

MPL-2.0 © Seth Holladay

Go make something, dang it.

Package Sidebar

Install

npm i hapi-align-json

Weekly Downloads

3

Version

4.0.0

License

MPL-2.0

Unpacked Size

20.2 kB

Total Files

4

Last publish

Collaborators

  • sholladay