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- isparamsobject already urlencoded.content_type- sets Content-Type.extended_result- marks that response should be extended and should contains:text- server response textmessage- server response messagecode- server response codeheaders- response http-headercontent_length- Content-Lengthcontent_type- Content-Type
Example
use "http"
http("http://jsonplaceholder.typicode.com/users", "POST", {"name": "OwnLang", "versionCode": 10}, def(v) {
println "Added: " + v
})
download(url) - downloads content by url as bytes array
Example
use "http"
use "files"
bytes = download("http://url")
f = fopen("file", "wb")
writeBytes(f, bytes)
flush(f)
fclose(f)
urlencode(str) - converts string to URL-format