☯ 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
] )
URL
String
- the fullURL
of the resource.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections.
debate.rest.head
( URL
, [options
] )
URL
String
- the fullURL
of the resource.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections.
debate.rest.post
( URL
, [options
], [body
] )
URL
String
- the fullURL
of the resource.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections. - [
body
]String
|Object
- The message body. Will be converted to a string
debate.rest.put
( URL
, [options
], [body
] )
URL
String
- the fullURL
of the resource.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections. - [
body
]String
|Object
- The message body. Will be converted to a string
debate.rest.del
( URL
, [options
] )
URL
String
- the fullURL
of the resource.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections.
debate.rest.custom
( URL
, method
, [options
], [body
] )
URL
String
- the fullURL
of the resource.method
String
- custom method.- [
options
]Object
- A hash of options as specified in thehttp
andhttps
standard request options. Note that when using SSL options withhttps
requests, you can specify the path anddebate
will read the files for you. You may also useignoreSSL: true
to allow untrusted connections. - [
body
]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.
## Example --- ```js // require debate var client = require('debate');
// 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);
});
## Tools --- Created with [Nodeclipse](https://github.com/Nodeclipse/nodeclipse-1) ([Eclipse Marketplace](http://marketplace.eclipse.org/content/nodeclipse), [site](http://www.nodeclipse.org))
Nodeclipse is free open-source project that grows with your contributions.