An open API service indexing awesome lists of open source software.

https://github.com/ramsunvtech/apicluster

API Endpoint Library - API Cluster is free and open source Javascript library for organizing endpoint in efficient way.
https://github.com/ramsunvtech/apicluster

Last synced: about 1 year ago
JSON representation

API Endpoint Library - API Cluster is free and open source Javascript library for organizing endpoint in efficient way.

Awesome Lists containing this project

README

          



# Api Cluster
**Endpoint Library**

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url]

[![NPM](https://nodei.co/npm/apicluster.png?downloads=true&downloadRank=true)](https://nodei.co/npm/apicluster/)

[downloads-image]: http://img.shields.io/npm/dm/apicluster.svg
[npm-url]: https://npmjs.org/package/apicluster
[npm-image]: http://img.shields.io/npm/v/apicluster.svg

[travis-url]: https://travis-ci.org/ramsunvtech/apicluster
[travis-image]: http://img.shields.io/travis/ramsunvtech/apicluster.svg

## What is API Cluster?
API Cluster is free and open source Javascript library for organizing endpoint in efficient way.

## Why API Cluster?
Add multiple groups for versioning.
Quit messing with concatenation on URL with + operator.
Available in (Node) Server side and (browser) Client Side.

# Getting Started

#### 1. Install api cluster globally (server side) or include the apicluster.js in your file.

```sh
$ npm install --global apicluster

```

#### 2. Create Config and define endpoints.

```javascript
ApiCluster
// Default Group.
.defaults({
name: 'mydefault',

config: {
'employee': 'emp',
'details': 'details',
'timesheet': 'timesheet'
},

endpoints: {
"empDetails": "_employee_/_details_/:empId/profile"
}
});
```

#### 2. Add multiple endpoints groups.

```javascript
ApiCluster
// Default Group.
.defaults({
name: 'mydefault',

config: {
'employee': 'emp',
'details': 'details',
'timesheet': 'timesheet'
},

endpoints: {
"empDetails": "_employee_/_details_/:empId/profile"
}
})
.addAnother({
name: 'v1',

config: {
'employee': 'emp/v1',
'details': 'detailed',
'timesheet': 'timesheet'
},

endpoints: {
"empDetails": "_employee_/_details_/:empId/profile"
}
})
.addAnother({
name: 'v2',

config: {
'employee': 'emp/v2',
'details': 'detailed',
'timesheet': 'timesheet'
},

endpoints: {
"empDetails": "_employee_/_details_/:empId/profile"
}
});
```

#### 4. Get your dynamic Endpoint URL from the Configured Endpoint list from Default Group defined in `defaults()` method.

```javascript
var empDetails = ApiCluster
.get('empDetails')
.arg({
'empId': 1000
})
.query({
'confirm': 'yes',
'testAccount': 'yes'
})
.url();
```
```
Expected Output: emp/details/1000/profile?confirm=yes&testAccount=yes
```

#### 5. Get Endpoint URL from the Configured Endpoint list from `v1` Group defined in `addAnother()` method.

```javascript
var empDetails = ApiCluster
.use('v1')
.get('empDetails')
.arg({
'empId': 1000
})
.query({
'confirm': 'yes',
'testAccount': 'yes'
})
.url();
```
```
Expected Output: emp/v1/detailed/1000/profile?confirm=yes&testAccount=yes
```

## Example on how to use it in Node.

```javascript
var http = require('http'),
ApiCluster = require('apicluster');

ApiCluster
// Default Group.
.defaults({
name: 'mydefault',

config: {
'employee': 'emp',
'details': 'details',
'timesheet': 'timesheet'
},

endpoints: {
"empDetails": "_employee_/_details_/:empId/profile"
}
});

//Lets define a port we want to listen to
const PORT = 9000;

// Function which handles requests and send response
function handleRequest(request, response) {
var empDetailURL = ApiCluster
.get('empDetails')
.arg({
'empId': 1000
})
.query({
'confirm': 'yes',
'testAccount': 'yes'
})
.url();
response.end('

Generated Endpoint URL:
'
+ empDetailURL + '

');
}

//Create a server
var server = http.createServer(handleRequest);

//Lets start our server
server.listen(PORT, function(){
// Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
```

## Want to contribute?

Anyone can help make this project better - check out the [Contributing guide](/CONTRIBUTING.md)!

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ramsunvtech/apicluster/trend.png)](https://bitdeli.com/free "Bitdeli Badge")