http

Contains network functions

Functions

http(url, ...) — performs GET-request to url.

http(url, method) - performs request with method (GET, POST, PUT, DELETE, PATCH, OPTIONS) to url.

http(url, callback) - performs GET-request to url, response will be send to function callback.

http(url, method, params) - performs request with given method and object params to url.

http(url, method, callback) - performs request with given method to url, response will be send to function callback.

http(url, method, params, callback) - performs request with given method and object params to url, response will be send to function callback.

http(url, method, params, options, callback) - performs request with given method, object params and connection options to url, response will be send to function callback.

Connection options is a object (map):

  • header - sets http-header (string or array).
  • encoded - is params object already urlencoded.
  • content_type - sets Content-Type.
  • extended_result - marks that response should be extended and should contains:
    • text - server response text
    • message - server response message
    • code - server response code
    • headers - response http-header
    • content_length - Content-Length
    • content_type - Content-Type
use http
http("http://jsonplaceholder.typicode.com/users", "POST", {"name": "OwnLang", "versionCode": 10}, def(v) {
  println "Added: " + v
})

httpSync(url, method = "GET", requestParams = {}, options = {}) 2.0.0 — Synchronous version of http function. See above for parameters description.

use http
extract(isOk, content) = httpSync("http://jsonplaceholder.typicode.com/users", "POST", {"name": "OwnLang", "versionCode": 10})
if (isOk) {
  println "Added: " + content
} else {
  println "Failure"
}

download(url) — downloads content by url as bytes array

use http, files
bytes = download("http://url")
f = fopen("file", "wb")
writeBytes(f, bytes)
flush(f)
fclose(f)

urlencode(str) — converts string to URL-format