Loading

Http extension

The Http extension allows to send any kind of Http request.

It adds the following functions to WarpScript:

The HTTP function sends an HTTP request, waits for the response then returns it. Its input is a MAP or arguments, and its output is a MAP of response items.

The input MAP can have these fields:

  • url (mandatory)
  • method
  • headers
  • body
  • chunk.size
  • chunk.macro
  • username
  • password

The response MAP can have these fields:

  • status.code
  • status.message
  • headers
  • content
  • chunk.number (if streaming)

The response is streamed if a positive chunk.size is provided.

More explanation can be found on the documention page of the function.

Installation

In a configuration file, usually etc/conf.d/70--extensions.conf, set:

warpscript.extension.http = io.warp10.script.ext.http.HttpWarpScriptExtension

Configuration

Your custom configurations can be stored in a new etc/conf.d/99-myWarp10.conf file. Your custom configurations will override all the predefined Warp 10 configurations.

// If set to true, HTTP requires the stack to be authenticated
#warpscript.http.authentication.required =
// If set, the capability <warpscript.http.capability> is checked to grant access to HTTP function
#warpscript.http.capability =
// Maximum number of HTTP calls, 1 by default, can be raised with capability http.requests
#warpscript.http.maxrequests =
// Maximum downloaded bytes by HTTP, 65536 by default, can be raised with capability http.size
#warpscript.http.maxsize =
// Maximum chunk size allowed when dowloading per chunk using HTTP, 65536 by default, can be raised with capability http.chunksize
#warpscript.http.maxchunksize =
// List of patterns to include/exclude for hosts, works the same way as webcall.host.patterns. Defaults to the value of webcall.host.patterns.
#warpscript.http.host.patterns =

Capabilities

This extension makes use of the following token's capabilities.

CapabilityDescription
http.requestsRaise the limit configured by warpscript.http.maxrequests
http.sizeRaise the limit configured by warpscript.http.maxsize
http.chunksizeRaise the limit configured by warpscript.http.maxchunksize
$If set, this capability is required to call HTTP

Example

This basic example will send a GET request.

// @endpoint http://yourinstance/api/v0/exec { 'url' 'https://httpbin.org/anything' } HTTP This example will send a POST request on another egress endpoint and will retrieve the result in streaming mode. // @endpoint http://yourinstance/api/v0/exec { 'method' 'POST' 'url' 'http://yourinstance/api/v0/exec' 'headers' {} 'body' '"" 1 100 <%25 TOSTRING + %25> FOR' 'chunk.size' 64 'chunk.macro' <% 'content' GET %> } HTTP