ArkScript
A small, fast, functional and scripting language for video games
http Client

http:headers:create

Create a header map to use with the http client.

Parameters They work as pairs with:

  • name: string
  • value: string

Return value UserType<httpHeaders>

Author

Example

(let headers (http:headers:create
# pair 0
"Accept-Encoding" "gzip, deflate"
# pair 1
"Content-Type" "application/json"
))

http:client:create

Create an http client to query a server.

Parameters

  • host: string, you must not put the protocol http:// nor https://
  • port: number

Return value List if the request succeeded: [status, body], otherwise nil

Author

Example

(let cli (http:client:create "localhost" 1234))

http:client:get

Get content from an online ressource.

Parameters

  • client: UserType<httpClient>
  • route: string
  • headers: UserType<httpHeaders>, optional, always come last

Return value List if the request succeeded: [status, body], otherwise nil

Author

Example

(let headers (http:headers:create
"Accept-Encoding" "gzip, deflate"
))
(let cli (http:client:create "localhost" 1234))
(mut output (http:client:get cli "/hi" headers))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # print the status

http:client:post

Make a POST request with either a String as the request's body or httpParams (request type would be application/x-www-form-urlencoded).

Parameters

  • client: UserType<httpClient>
  • route: string
  • bodyOrParams: string if given a request body, UserType<httpParams> if given parameters
  • mimetype: string, optional (defaults to text/plain)
  • headers: UserType<httpHeaders>, optional, always come last

Return value List if the request succeeded: [status, body], otherwise nil

Author

Example

(let cli (http:client:create "localhost" 1234))
# the "text/plain" argument is optional here
(mut output (http:client:post cli "/form" "hello world!" "text/plain"))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # prints status of the request
(let params (http:params:create
"name" "john"
"note" "coder"
))
# here, no need to add the content-type because we are sending parameters
(set output (http:client:post cli "/form-bis" params))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # prints status of the request

http:client:put

Make a PUT request with either a String as the request's body or httpParams (request type would be application/x-www-form-urlencoded).

Parameters

  • client: UserType<httpClient>
  • route: string
  • body: string
  • mimetype: string, optional (defaults to text/plain)
  • headers: UserType<httpHeaders>, optional, always come last

Return value List if the request succeeded: [status, body], otherwise nil

Author

Works exactly like http:client:post.

http:client:delete

Make a DELETE request with a String as the request's body.

Parameters

  • client: UserType<httpClient>
  • route: string
  • body: string
  • mimetype: string, optional (defaults to text/plain)
  • headers: UserType<httpHeaders>, optional, always come last

Return value List if the request succeeded: [status, body], otherwise nil

Author

Example

(let cli (http:client:create "localhost" 1234))
# the "text/plain" argument is optional here
# if we were to add headers, they would come last
(mut output (http:client:delete cli "/delete-me" "hello world!" "text/plain"))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # prints status of the request

http:params:create

Used to create a parameter list for a POST/PUT/DELETE request (application/x-www-form-urlencoded).

It works like http:headers:create, you need to give an even number of Strings (key -> value mapping).

Return value UserType<Params>

Author

Example

(let params (http:params:create
"name" "john"
"note" "coder"
))

http:params:toList

Convert an httpParams to an ArkScript readable list.

Parameters

Return value List

Author

http:client:setFollowLocation

Choose if the request should follow the redirection or not.

Parameters

  • followLocation: bool

Return value nil

Author

Example

(let cli (http:client:create "yahoo.com" 80))
(mut output (http:client:get cli "/"))
(print (@ output 0)) # status: 301
(http:client:setFollowLocation cli true)
(set output (http:client:get cli "/"))
(print (@ output 0)) # status: 200

http:client:setConnectionTimeout

Set the connection timeout.

Parameters

  • seconds: number
  • microseconds: number, for even more precision ; can be 0

Return value nil

Author

http:client:setReadTimeout

Set the read timeout.

Parameters

  • seconds: number
  • microseconds: number, for even more precision ; can be 0

Return value nil

Author

http:client:setWriteTimeout

Set the write timeout.

Parameters

  • seconds: number
  • microseconds: number, for even more precision ; can be 0

Return value nil

Author

http:client:setBasicAuth

Set the basic authentification username and password for a client to use.

Parameters

  • username: string
  • password: string

Return value nil

Author

http:client:setBearerTokenAuth

Set the basic bearer token authentification for a client to use.

Parameters

  • token: string

Return value nil

Author

http:client:setKeepAlive

Tell the server to keep the connection alive or not.

Parameters

  • keepAlive: bool

Return value nil

Author

http:client:setProxy

Set the parameters (host and port) of a proxy, to be used by a client.

Parameters

  • host: string, address of the proxy, eg cache.edu.mit.org
  • port: number

Return value nil

Author

http:client:setProxyBasicAuth

Set the basic proxy authentification username and password for a client to use.

Parameters

  • username: string
  • password: string

Return value nil

Author

http:client:setProxyBearerTokenAuth

Set the basic proxy bearer token authentification for a client to use.

Parameters

  • token: string

Return value nil

Author