1.0.3 • Published 4 years ago
object-to-api v1.0.3
Object-To-API
Do you happen to have a Javascript package that you want to wrap in a REST service? If so- this module is exactly for you!
Installation
using npm
npm install --save object-to-api
using yarn
yarn add object-to-api
Usage
Just 6 lines of code-
import express from 'express';
import objectToApi from 'object-to-api';
const someApiObject = {
someInternalObject: {
someFunc: (arg1, arg2) => {}
}
};
const app = express();
app.use('/', objectToApi(someApiObject));
app.listen({port: 3000});
Now you have an ExpressJS server that wraps your API.
The structure of your new API is- (POST) http://localhost:3000/someInternalObject/someFunc And it expects a body, which is an array of the arguments of the function.
Swagger
You can expose your api via swagger Swagger is peerDependency
Swagger docs on http://localhost:3000/api-docs!
npm install --save-dev swagger?
app.use('/', objectToApi(someApiObject, {swagger: true}));
extend swagger
app.use('/', objectToApi(someApiObject, {swagger: swaggerSettings}));
Contributing
- 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
Credits
TODO: Write credits
License
MIT License
Enjoy!!!