HTTP Client

The HTTP Client can help you build application integrations, consuming REST or SOAP web services can be an easy task.

All invocations of the HTTPClient interface send an HTTP request over the wire. The method, contentType and headers used to create the request are based on the options.

You can send a GET request easily:

var data = require("inpaas.http.client").
            get("https://www.someotherserver.com/api/myservice");

Or a POST request with JSON data:

var data = require("inpaas.http.client").
            post("https://www.someotherserver.com/api/myservice", {
                "some-id": 16,
                "some-text": "Hello Service!"
            });

📘

Use JSON

POST/PUT Requests are sent in JSON format and with the content-type: application/json and accepts: application/json in the header. All data returned are expected to be in JSON format.

See http://json.org for more information.

Helper Methods

get(string)

Sends a GET request and parse the response as JSON.

post(string, data)

Sends a POST request, with the object in JSON format and parse the response as JSON.

put(string, data)

Sends a PUT request, with the object in JSON format and parse the response as JSON.

delete(string)

Sends a GET request and parse the response as JSON.

Advanced Requests

Other complex requests may be made using the execute method:

execute(options)

Sends an HTTP request based on the options provided.

url: String

The destination URL.

method: String

The HTTP method to be used in the request (usually GET, POST, PUT or DELETE).

timeout: Integer

The timeout in seconds before the request is aborted.
Default: 30 seconds.

contentType: String

The MIME Content-Type of the request.
Default: application/json

headers: Object

A key/value pair with all the headers that should be sent with the request.

data: Object

A Object or String ot be sent with the request. If an Object is sent, the Service will Stringify it in JSON format before sending.

responseProcessor: Function

A function that will proccess/parse the response received from the request and returns data. Use this if you want to parse the content of the return instead of a JSON parsing.

requestBodyProcessor: Function

A function that will proccess the request before invocation. Use this if you want to transform the content of the payload before sending over.

Updated less than a minute ago

HTTP Client


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.