https://github.com/erdian718/lmodhttpclient
http.Client bindings for Lua.
https://github.com/erdian718/lmodhttpclient
go http http-client lua
Last synced: 5 months ago
JSON representation
http.Client bindings for Lua.
- Host: GitHub
- URL: https://github.com/erdian718/lmodhttpclient
- Owner: erdian718
- License: zlib
- Created: 2019-06-08T06:45:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-20T16:03:55.000Z (over 2 years ago)
- Last Synced: 2025-01-08T06:31:52.583Z (about 1 year ago)
- Topics: go, http, http-client, lua
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lmodmsgpack
`http.Client` bindings for [Lua](https://github.com/ofunc/lua).
## Usage
```go
package main
import (
"ofunc/lmodhttpclient"
"ofunc/lua/util"
)
func main() {
l := util.NewState()
l.Preload("http/client", lmodhttpclient.Open)
util.Run(l, "main.lua")
}
```
```lua
local io = require 'io'
local client = require 'http/client'
local resp = client.get('https://github.com/ofunc/lmodhttpclient')
io.copy(resp, io.stdout)
resp:close()
```
## Dependencies
* [ofunc/lua](https://github.com/ofunc/lua)
* [publicsuffix](https://golang.org/x/net/publicsuffix)
## Documentation
### client.head(url)
Issues a `HEAD` to the specified `url`.
### client.get(url)
Issues a `GET` to the specified `url`.
### client.post(url, x[, y])
Issues a `POST` to the specified `url`.
`x` is a `Content-Type` and `y` is a `io.reader`.
Or `x` is a form data.
### client.fetch(options)
Sends an HTTP request and returns an HTTP response.
```
options.url: The path name to send the request to.
options.method: The HTTP method to use.
options.body: Body that you want to add to your request.
options.header: Header to append to the request before sending it.
```
### client.encode(data)
Encodes the `data` into `URL encoded` form.