https://github.com/lambda2/apiize
Turn json files into explorable API's
https://github.com/lambda2/apiize
Last synced: 5 months ago
JSON representation
Turn json files into explorable API's
- Host: GitHub
- URL: https://github.com/lambda2/apiize
- Owner: lambda2
- License: mit
- Created: 2016-06-03T08:33:59.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-25T17:38:23.000Z (almost 10 years ago)
- Last Synced: 2025-10-19T23:39:20.627Z (8 months ago)
- Language: JavaScript
- Size: 3.14 MB
- Stars: 45
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# apiize [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]
**Turn any JSON file into a full, explorable, REST API.**
## Presentation
#### Start apiize on a JSON file or url

#### And make requests on it

## Install
```sh
$ npm install -g apiize
```
## Command line usage
- Start a new server on a given JSON file or url
```bash
$ apiize 'https://raw.githubusercontent.com/lambda2/apiize/master/test/datasets/punchlines.json'
___ _ _
/ _ \ (_|_)
/ /_\ \_ __ _ _ _______
| _ | '_ \| | |_ / _ \
| | | | |_) | | |/ / __/
\_| |_/ .__/|_|_/___\___|
| |
|_|
π« Express has taken the stage and is listening on port 1313
β GET /api/contents Return all the contents
β GET /api/contents/:id Return the given contents
β GET /api/tags Return all the tags
β GET /api/tags/:id Return the given tags
β GET /api/authors Return all the authors
β GET /api/authors/:id Return the given authors
β GET /api/albums Return all the albums
β GET /api/albums/:id Return the given albums
β GET /api/titles Return all the titles
β GET /api/titles/:id Return the given titles
β GET /api/ Return all items
β GET /api/random A random item
```
- Make requests on it
```bash
$ curl -H "Accept: application/json" "localhost:1313/"
{"endpoints":[{"url":"/api/contents","description":"Return all the contents"},{"url":"/api/contents/:id","description":"Return the given contents"},{"url":"/api/tags","description":"Return all the tags"},{"url":"/api/tags/:id","description":"Return the given tags"},{"url":"/api/authors","description":"Return all the authors"},{"url":"/api/authors/:id","description":"Return the given authors"},{"url":"/api/albums","description":"Return all the albums"},{"url":"/api/albums/:id","description":"Return the given albums"},{"url":"/api/titles","description":"Return all the titles"},{"url":"/api/titles/:id","description":"Return the given titles"},{"url":"/api/","description":"Return all items"},{"url":"/api/random","description":"A random item"}]}%
```
## Usage
```js
const Apiize = require('apiize');
// Here is the default options
const options = {
verbose: false, // Output more verbose requests
prefix: 'api', // The root endpoint of the API
port: 1313 // The express server port.
};
// Turn the 'http://example.org/file.json' file into an API
let apiize = new Apiize('http://example.org/file.json', options);
// When apiize is ready
apiize.on('ready', function (server) {
server.serve(); // run the server
});
```
## API
```js
var Apiize = require('apiize');
var api = new Apiize(link, options);
```
------------------
### Events
#### ready
Triggered when the file or the link is fully loaded, and the express server is ready to be started.
```js
var api = new Apiize(link, options);
api.on('ready', function (server) {
server.serve(); // run the server
});
```
------------------
### Methods
#### new Apiize(link, options)
Create a new Apiize object using the given `link` and `options`.
The `link` argument must be a string of a JSON file or a JSON URL.
> Apiize accepts these properties in the options object.
- verbose
> Defaults to `false`, add a more verbose logging of incoming requests.
- Without `verbose`:
`GET / 200 146 - 6.079 ms`
- With `verbose`:
`::1 - - [25/Jun/2016:15:41:06 +0000] "GET / HTTP/1.1" 200 750 "-" "curl/7.43.0"`
- prefix
> Set the root path of the generated api routes. Defaults to `api`.
- port
> Set the express server port. Defaults to `1313`.
#### on(event, callback)
Triggered when an event is emmmited (e.g., the `ready` event).
#### serve()
Start the express server. Must be called when the `ready` event is called.
------------------
## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
$ npm install
$ npm test
```
## People
[AndrΓ© Aubin](https://github.com/lambda2) [![Andre's Gratipay][gratipay-image-lambda2]][gratipay-url-lambda2]
[List of all contributors](https://github.com/lambda2/apiize/graphs/contributors)
## License
MIT Β© [Andre Aubin](http://andral.kiwi)
[npm-image]: https://badge.fury.io/js/apiize.svg
[npm-url]: https://npmjs.org/package/apiize
[travis-image]: https://travis-ci.org/lambda2/apiize.svg?branch=master
[travis-url]: https://travis-ci.org/lambda2/apiize
[daviddm-image]: https://david-dm.org/lambda2/apiize.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/lambda2/apiize
[coveralls-image]: https://coveralls.io/repos/github/lambda2/apiize/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/lambda2/apiize?branch=master
[gratipay-image-lambda2]: https://img.shields.io/gratipay/lambda2.svg
[gratipay-url-lambda2]: https://gratipay.com/lambda2/