URL Fetch extension
WEBCALL allows us to send asynchronously a request to a distance web service, but it ignores the answer. URLFETCH is designed to send requests synchronously. It blocks until you get an answer from the server.
You need to be authenticated with a valid token with the function AUTHENTICATE before using URLFETCH.
URLFETCH does a GET request on the URL input.
This extension adds the following functions to WarpScript:
URLFETCH always add the following headers:
User-Agent: Java/1.8.0_171
Host: localhost:9001
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Installation
In a configuration file, usually etc/conf.d/70--extensions.conf
, set:
// URLFETCH, MAXURLFETCHCOUNT, MAXURLFETCHSIZE
warpscript.extension.urlfetch = io.warp10.script.ext.urlfetch.UrlFetchWarpScriptExtension
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.
// URLFETCH, MAXURLFETCHCOUNT, MAXURLFETCHSIZE
warpscript.extension.urlfetch = io.warp10.script.ext.urlfetch.UrlFetchWarpScriptExtension
// Maximum number of URLFETCH calls, 64 by default for soft and hard
warpscript.urlfetch.limit = 10
warpscript.urlfetch.limit.hard = 1000
// Maximum downloaded bytes by URLFETCH, 1000000 by default for soft and hard
warpscript.urlfetch.maxsize = 1000000
warpscript.urlfetch.maxsize.hard = 1000000000
// 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.urlfetch.host.patterns = .*
Example
This WarpScript will try to fetch your public IP on different services.