Skip to content

Instantly share code, notes, and snippets.

@ramsunvtech
Created November 28, 2015 14:34
Show Gist options
  • Save ramsunvtech/292156eaf4c5f6b40023 to your computer and use it in GitHub Desktop.
Save ramsunvtech/292156eaf4c5f6b40023 to your computer and use it in GitHub Desktop.
Api Cluster Usage in NodeJS
var http = require('http'),
ApiCluster = require('apicluster');
ApiCluster
.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('<h1>Generated Endpoint URL:<br> '
+ empDetailURL + '</h1>');
}
//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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment