BQN HTTP library, from libcurl FFI bindings
config.bqn | ||
curl.bqn | ||
ffi.bqn | ||
LICENSE | ||
README.org | ||
tests.bqn | ||
utils.bqn |
BQN HTTP library
FFI bindings to libcurl for BQN.
Configuration
Set the location of the libcurl.so
library in config.bqn.
Making requests
Only GET and POST requests are implemented at this time.
⟨Get,Post⟩←•Import"curl.bqn"
Simple GET requests:
r←Get"https://httpbin.org/get"
You can pass headers as a left argument:
r←⟨"Content-Type: application/json"⟩Get"https://httpbin.org/get"
Arguments, port number, etc, can be included in the URL.
For POST requests, pass data as an additional string parameter. It will not be converted or encoded in any way.
r←⟨"Content-Type: application/json"⟩Post"https://httpbin.org/post"‿"{""key"": ""value""}"
Response objects
The response object is a namespace with the following elements:
code
: the response code.headers
: the response headers as a single string, separated by newlines.content
: the response content, as raw bytes.time
: the time the request took, in seconds.
If your endpoint returns text, you can use FromBytes
from
bqn-libs/strings.bqn to decode UTF-8.
Tests
Run a local httpbin.org instance with Docker:
docker run -p 8080:80 kennethreitz/httpbin
The tests can be run with bqn tests.bqn
.