debate

0.0.3 • Public • Published

☯ 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 full URL of the resource.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: true to allow untrusted connections.

debate.rest.head( URL, [options] )

  • URL String - the full URL of the resource.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: true to allow untrusted connections.

debate.rest.post( URL, [options], [body] )

  • URL String - the full URL of the resource.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: 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 full URL of the resource.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: 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 full URL of the resource.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: true to allow untrusted connections.

debate.rest.custom( URL, method, [options], [body] )

  • URL String - the full URL of the resource.
  • method String - custom method.
  • [options] Object - A hash of options as specified in the http and https standard request options. Note that when using SSL options with https requests, you can specify the path and debate will read the files for you. You may also use ignoreSSL: 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 object
  • response - The complete response object
  • code - The HTTP status code
  • rawData - The unparsed/unformatted response data
  • data - 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.

Package Sidebar

Install

npm i debate

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • vbranden