Coder Social home page Coder Social logo

gluahttp's Introduction

gluahttp

gluahttp provides an easy way to make HTTP requests from within GopherLua.

Installation

go get github.com/cjoudrey/gluahttp

Usage

import "github.com/yuin/gopher-lua"
import "github.com/cjoudrey/gluahttp"

func main() {
    L := lua.NewState()
    defer L.Close()

    L.PreloadModule("http", NewHttpModule(&http.Client{}).Loader)

    if err := L.DoString(`

        local http = require("http")

        response, error_message = http.request("GET", "http://example.com", {
            query="page=1",
            timeout="30s",
            headers={
                Accept="*/*"
            }
        })

    `); err != nil {
        panic(err)
    }
}

API

http.delete(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.get(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.head(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.patch(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
body String Request body.
form String Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.post(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
body String Request body.
form String Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.put(url [, options])

Attributes

Name Type Description
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
body String Request body.
form String Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.request(method, url [, options])

Attributes

Name Type Description
method String The HTTP request method
url String URL of the resource to load
options Table Additional options

Options

Name Type Description
query String URL encoded query params
cookies Table Additional cookies to send with the request
body String Request body.
form String Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded
headers Table Additional headers to send with the request
timeout Number/String Request timeout. Number of seconds or String such as "1h"
auth Table Username and password for HTTP basic auth. Table keys are user for username, pass for passwod. auth={user="user", pass="pass"}

Returns

http.response or (nil, error message)

http.request_batch(requests)

Attributes

Name Type Description
requests Table A table of requests to send. Each request item is by itself a table containing http.request parameters for the request

Returns

[http.response] or ([http.response], [error message])

http.response

The http.response table contains information about a completed HTTP request.

Attributes

Name Type Description
body String The HTTP response body
body_size Number The size of the HTTP reponse body in bytes
headers Table The HTTP response headers
cookies Table The cookies sent by the server in the HTTP response
status_code Number The HTTP response status code
url String The final URL the request ended pointing to after redirects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.