atomvm_gleam/http
Types
Request body for request.
pub type Body {
Empty
Bytes(BitArray)
Stream
}
Constructors
-
EmptyNo body (
undefined/nilupstream). -
Bytes(BitArray)Inline body;
Content-Lengthis set automatically. -
StreamStreamed upload via
stream_request_body. Pair with an explicitContent-Lengthheader.
Opaque HTTP connection handle.
pub type Connection
Errors from ahttp_client.
pub type Error {
Failed
NotSupported
Badarg
Timeout
Other(String)
}
Constructors
-
Failed -
NotSupported -
Badarg -
Timeout -
Other(String)
pub type Response {
Status(ref: Ref, code: Int)
Header(ref: Ref, name: BitArray, value: BitArray)
HeaderContinuation(ref: Ref, name: BitArray, value: BitArray)
TrailerHeader(ref: Ref, name: BitArray, value: BitArray)
Data(ref: Ref, body: BitArray)
Done(ref: Ref)
}
Constructors
-
Status(ref: Ref, code: Int) -
Header(ref: Ref, name: BitArray, value: BitArray) -
HeaderContinuation(ref: Ref, name: BitArray, value: BitArray)Deprecated: AtomVM 0.7 no longer emits obs-fold / header continuation. Kept for binary compatibility with older response lists.
-
TrailerHeader(ref: Ref, name: BitArray, value: BitArray)Trailer field after a chunked body (0.7).
-
Data(ref: Ref, body: BitArray) -
Done(ref: Ref)
Outcome of feeding one mailbox message into stream.
pub type StreamEvent {
Responses(Connection, List(Response))
Closed(Connection)
Unknown
}
Constructors
-
Responses(Connection, List(Response))Parsed HTTP response pieces for this message.
-
Closed(Connection)Peer closed after a complete response (or with no in-flight parse).
-
UnknownMessage was not a socket message for this connection.
Values
pub fn close(conn: Connection) -> Result(Nil, Error)
Close the connection.
See ahttp_client:close/1.
pub fn connect(
protocol: Protocol,
host: String,
port: Int,
active: Bool,
verify: option.Option(Verify),
) -> Result(Connection, Error)
Connect to an HTTP(S) server.
pub fn recv(
conn: Connection,
len: Int,
) -> Result(#(Connection, List(Response)), Error)
Receive and parse up to len bytes (0 = all pending).
See ahttp_client:recv/2.
pub fn request(
conn: Connection,
method: String,
path: String,
headers: List(#(String, String)),
body: Body,
) -> Result(#(Connection, Ref), Error)
Send an HTTP request.
Pass Empty for no body, Bytes for an inline payload, or
Stream to upload with stream_request_body.
pub fn stream(
conn: Connection,
message: message,
) -> Result(StreamEvent, Error)
pub fn stream_request_body(
conn: Connection,
ref: Ref,
chunk: BitArray,
) -> Result(#(Connection, Ref), Error)