Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sholladay/hapi-align-json
Respond with beautiful JSON
https://github.com/sholladay/hapi-align-json
align alignment dx hapi indent json plugin
Last synced: 23 days ago
JSON representation
Respond with beautiful JSON
- Host: GitHub
- URL: https://github.com/sholladay/hapi-align-json
- Owner: sholladay
- License: mpl-2.0
- Created: 2017-02-21T10:19:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T18:07:12.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T00:28:54.939Z (9 months ago)
- Topics: align, alignment, dx, hapi, indent, json, plugin
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-align-json [![Build status for hapi Align JSON](https://travis-ci.com/sholladay/hapi-align-json.svg?branch=master "Build Status")](https://travis-ci.com/sholladay/hapi-align-json "Builds")
> Respond with beautiful JSON
## Why?
- Quick alternative to HTML in some cases.
- Optimize your API for readability.
- Has the best formatting.## Install
```sh
npm install hapi-align-json
```## Usage
Register the plugin on your server to enable beautiful JSON responses.
```js
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.
```json
{
"foo" : "bar",
"ping" : "pong",
"wee" : {
"hi" : "bye",
"tea" : "time"
},
"knick" : "knack",
"back" : "pack"
}
```## Contributing
See our [contributing guidelines](https://github.com/sholladay/hapi-align-json/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details.
1. [Fork it](https://github.com/sholladay/hapi-align-json/fork).
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](https://github.com/sholladay/hapi-align-json/compare "Submit code to this project for review").## License
[MPL-2.0](https://github.com/sholladay/hapi-align-json/blob/master/LICENSE "License for hapi-align-json") © [Seth Holladay](https://seth-holladay.com "Author of hapi-align-json")
Go make something, dang it.