http

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-lua-http

A GopherLua module for making HTTP requests from Lua scripts.

Installation

go get github.com/kerimovok/go-lua-http

Usage

In Go
import (
    lua "github.com/yuin/gopher-lua"
    http "github.com/kerimovok/go-lua-http"
)

L := lua.NewState()
defer L.Close()

// Preload the http module
L.PreloadModule("http", http.Loader)

// Now Lua scripts can use require("http")
L.DoString(`
    local http = require("http")
    local resp = http.get("https://api.example.com/data")
    print(resp.status) -- 200
    print(resp.body)
`)
In Lua
local http = require("http")

-- GET request
local resp, err = http.get("https://api.example.com/users/1")
if err then
    error("Request failed: " .. err)
end
print("Status:", resp.status)
print("Body:", resp.body)

-- POST request with headers
local headers = {
    ["Authorization"] = "Bearer token123",
    ["Content-Type"] = "application/json"
}
local resp, err = http.post(
    "https://api.example.com/users",
    '{"name":"John","email":"john@example.com"}',
    headers
)

-- PUT request
local resp, err = http.put(
    "https://api.example.com/users/1",
    '{"name":"John Doe"}',
    {}
)

-- DELETE request
local resp, err = http.delete("https://api.example.com/users/1", {})

Functions

http.get(url, headers?)

Performs a GET request.

  • Parameters:
    • url (string): The URL to request
    • headers (table, optional): Headers as key-value pairs
  • Returns:
    • table: Response table with status, status_text, body, and headers
    • string (error): Error message if request fails
http.post(url, body, headers?)

Performs a POST request.

  • Parameters:
    • url (string): The URL to request
    • body (string): Request body
    • headers (table, optional): Headers as key-value pairs
  • Returns:
    • table: Response table
    • string (error): Error message if request fails
http.put(url, body, headers?)

Performs a PUT request.

  • Parameters:
    • url (string): The URL to request
    • body (string): Request body
    • headers (table, optional): Headers as key-value pairs
  • Returns:
    • table: Response table
    • string (error): Error message if request fails
http.delete(url, headers?)

Performs a DELETE request.

  • Parameters:
    • url (string): The URL to request
    • headers (table, optional): Headers as key-value pairs
  • Returns:
    • table: Response table
    • string (error): Error message if request fails

Response Table

All HTTP functions return a response table with the following fields:

  • status (number): HTTP status code (e.g., 200, 404, 500)
  • status_text (string): HTTP status text (e.g., "200 OK")
  • body (string): Response body as string
  • headers (table): Response headers as key-value pairs

Notes

  • Default timeout is 30 seconds
  • If Content-Type header is not provided and body exists, it defaults to application/json
  • All requests are synchronous and will block until completion or timeout

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loader

func Loader(L *lua.LState) int

Loader loads the http module

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址