https://github.com/tiaanduplessis/apit
JSON/Object to REST API with zero effort
https://github.com/tiaanduplessis/apit
api brewski cli localhost server
Last synced: 11 months ago
JSON representation
JSON/Object to REST API with zero effort
- Host: GitHub
- URL: https://github.com/tiaanduplessis/apit
- Owner: tiaanduplessis
- License: mit
- Created: 2017-08-03T12:16:44.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-07T02:54:59.000Z (about 6 years ago)
- Last Synced: 2025-07-03T05:49:05.081Z (12 months ago)
- Topics: api, brewski, cli, localhost, server
- Language: JavaScript
- Homepage:
- Size: 216 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
apit
JSON/Object to REST API with zero effort
Table of Contents
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
```sh
$ npm install apit
# OR
$ yarn add apit
```
Or to use as CLI:
```sh
$ npm -g install apit
# OR
$ yarn global add apit
```
## Usage
```js
const apit = require('apit')
const data = {
posts: {
foo: {
message: 'hello'
}
},
other: 'foo',
baz: [1,2,3],
food: {
steal: {
healthy: true
}
}
}
apit(data)
{"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`:
```sh
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}
```
## Caveats
Currently only `GET` requests are supported.
## Contributing
Contributions are welcome!
1. Fork it.
2. Create your 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 :D
Or open up [a issue](https://github.com/tiaanduplessis/apit/issues).
## License
Licensed under the MIT License.