Table of Contents
JSON/Object to REST API with zero effort
Built with ❤︎ by tiaanduplessis and contributors
Table of Contents
About
The package takes json
or plain object
and turns it into a RESTful API server running on a given port (defaults to 8000
).
Install
$ npm install apit# OR $ yarn add apit
Or to use as CLI:
$ npm -g install apit# OR $ yarn global add apit
Usage
const apit = const data = posts: foo: message: 'hello' other: 'foo' baz: 123 food: steal: healthy: true "pid":54578"hostname":"Tiaan-FF-Mac.local""name":"brewski""level":30"time":1501775589826"msg":"Server listening at http://localhost:3000""v":1
The above example will create the following routes with associated values:
- / - {"posts":{"foo":{"message":"hello"}},"other":"foo","baz":[1,2,3],"food":{"steal":{"healthy":true}}}
- /posts - {"foo":{"message":"hello"}}
- /posts/foo - {"message":"hello"}
- /posts/foo/message - "hello"
- /other - "foo"
- /baz - [1,2,3]
- /food - {"steal":{"healthy":true}}
- /food/steal - {"healthy":true}
- /food/steal/healthy - true
If you install the module globally, you can also use it with a json
file or module that exports a object
:
apit --file=example.json# {"pid":56017,"hostname":"Tiaan-FF-Mac.local","name":"brewski","level":30,"time":1501776268494,"msg":"Server listening at http://localhost:8000","v":1}
Contributing
Contributions are welcome!
- Fork it.
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Or open up a issue.
License
Licensed under the MIT License.