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.
- Host: GitHub
- URL: https://github.com/ramsunvtech/apicluster
- Owner: ramsunvtech
- License: mit
- Created: 2015-11-10T19:19:19.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-22T14:52:09.000Z (over 10 years ago)
- Last Synced: 2025-03-24T01:42:37.296Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://apicluster.js.org/
- Size: 77.1 KB
- Stars: 7
- Watchers: 2
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Contributing: CONTRIBUTING.md
- License: LICENSE
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]
[](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)!
[](https://bitdeli.com/free "Bitdeli Badge")