debate v0.0.3
☯ debate ☯
debate is a promised based web service client. The goal for this project is to provide several client types but initially REST is the only supported protocol.
- See the WIKI for full documentation
- And the Change Log for what's new
Documentation
debate.rest.get( URL, options )
URLString- the fullURLof the resource.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.
debate.rest.head( URL, options )
URLString- the fullURLof the resource.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.
debate.rest.post( URL, options, body )
URLString- the fullURLof the resource.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.body(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) |Object- The message body. Will be converted to a string
debate.rest.put( URL, options, body )
URLString- the fullURLof the resource.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.body(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) |Object- The message body. Will be converted to a string
debate.rest.del( URL, options )
URLString- the fullURLof the resource.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.
debate.rest.custom( URL, method, options, body )
URLString- the fullURLof the resource.methodString- custom method.options(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - A hash of options as specified in thehttpandhttpsstandard request options. Note that when using SSL options withhttpsrequests, you can specify the path anddebatewill read the files for you. You may also useignoreSSL: trueto allow untrusted connections.body(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) |Object- The message body. Will be converted to a string
Ouput
All API methods output an object containing
request- The complete request objectresponse- The complete response objectcode- The HTTP status coderawData- The unparsed/unformatted response datadata- The parsed/formatted data
Formatters
A an additional formatters option can be added to the options hash. The key should be the content-type and its value should be a function that takes rawData as its only argument and returns the formatted data/object. By default a formatter for application/json is added if not specified.
// get request client.rest.get('http://localhost:8080/api/resource').then(function(res) { console.log(res.status, res.data); });
// post request var body = { name: 'John Doe' };
client.rest.post('http://localhost:8080/api/resource', null, body).then(function(res) { console.log(res.status, res.data); });
<br>
## Example with Custom formatter
---
```js
// require debate
var client = require('debate');
// create custom options
var options = {
formatters: {
'application/json+custom': function(data) {
try {
var parsed = JSON.parse(data);
delete parsed.id;
return parsed;
}
catch(err) {
return data;
}
}
}
};
// get request
client.rest.get('http://localhost:8080/api/resource', options).then(function(res) {
console.log(res.status, res.data);
});Nodeclipse is free open-source project that grows with your contributions.