GlyEngine 0.1.2
Create games and apps with lua
Loading...
Searching...
No Matches
Http

Functions

local function json ()
 json response
 
local function noforce ()
 not force protocol
 
local function fast ()
 reduced response
 
local function param (name, value)
 
local function header (name, value)
 
local function body (content)
 
local function success (handler_func)
 
local function failed (handler_func)
 
local function error (handler_func)
 

Detailed Description

Precondition
require http

GET

std.http.get('https://api.github.com/zen')
:run()

POST

std.http.post('https://example.com.br'):json()
:header('Authorization', 'Basic dXN1YXJpb3NlY3JldG86c2VuaGFzZWNyZXRh')
:param('telefone', '188')
:body({
user = 'Joao',
message = 'Te ligam!'
})
:run()
local function json()
json response
local function header(name, value)
local function body(content)
local function param(name, value)

Http requests

  • std.http.get
  • std.http.head
  • std.http.post
  • std.http.put
  • std.http.delete
  • std.http.patch

Http responses

  • local handlers
    std.http.get('http://pudim.com.br')
    :success(function()
    print('2xx callback')
    end)
    :failed(function()
    print('4xx / 5xx callback')
    end)
    :error(function()
    print('eg. to many redirects')
    end)
    :run()
    local function success(handler_func)
    local function failed(handler_func)
    local function error(message)
    local function print(pos_x, pos_y, text)
    std.text.print
  • global handler
    local function http(std, game)
    if std.http.error then
    print('eg. https is not supported')
    end
    if std.http.ok then
    print('2xx status')
    end
    if std.http.status > 400 then
    print('2xx / 5xx status')
    end
    end

Function Documentation

◆ body()

local function body ( content )
Precondition
you can directly place a table in your body which will automatically be encoded and passed the header Content-Type: application/json, but for this you previously need to require json
Examples
std.http.post('http://example.com/plain-text'):body('foo is bar'):run()
std.http.post('http://example.com/json-object'):body({foo = bar}):run()

◆ error()

local function error ( handler_func )

◆ failed()

local function failed ( handler_func )

◆ fast()

local function fast ( )

disconnect when receiving status

◆ header()

local function header ( name ,
value  )
Eaxmaple
std.http.post('http://example.com/secret-ednpoint')
:header('Authorization', 'Bearer c3VwZXIgc2VjcmV0IHRva2Vu')
:run()

◆ json()

local function json ( )

decode body to table on response

◆ noforce()

local function noforce ( )

By default, requests follow the protocol (HTTP or HTTPS) based on their origin (e.g., HTML5). This setting allows opting out of that behavior and disabling automatic protocol enforcement.

◆ param()

local function param ( name ,
value  )

◆ success()

local function success ( handler_func )