2024-07-01 20:58:00 +00:00
|
|
|
interface http-client {
|
|
|
|
/// An HTTP request.
|
|
|
|
record http-request {
|
2024-08-12 14:36:49 +00:00
|
|
|
/// The HTTP method for the request.
|
|
|
|
method: http-method,
|
2024-07-01 20:58:00 +00:00
|
|
|
/// The URL to which the request should be made.
|
|
|
|
url: string,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// The headers for the request.
|
2024-08-12 14:36:49 +00:00
|
|
|
headers: list<tuple<string, string>>,
|
|
|
|
/// The request body.
|
|
|
|
body: option<list<u8>>,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// The policy to use for redirects.
|
|
|
|
redirect-policy: redirect-policy,
|
2024-08-12 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// HTTP methods.
|
|
|
|
enum http-method {
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `GET`
|
2024-08-12 14:36:49 +00:00
|
|
|
get,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `HEAD`
|
|
|
|
head,
|
|
|
|
/// `POST`
|
2024-08-12 14:36:49 +00:00
|
|
|
post,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `PUT`
|
2024-08-12 14:36:49 +00:00
|
|
|
put,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `DELETE`
|
2024-08-12 14:36:49 +00:00
|
|
|
delete,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `OPTIONS`
|
2024-08-12 14:36:49 +00:00
|
|
|
options,
|
2024-08-13 14:40:21 +00:00
|
|
|
/// `PATCH`
|
2024-08-12 14:36:49 +00:00
|
|
|
patch,
|
2024-07-01 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2024-08-13 14:40:21 +00:00
|
|
|
/// The policy for dealing with redirects received from the server.
|
|
|
|
variant redirect-policy {
|
|
|
|
/// Redirects from the server will not be followed.
|
|
|
|
///
|
|
|
|
/// This is the default behavior.
|
|
|
|
no-follow,
|
|
|
|
/// Redirects from the server will be followed up to the specified limit.
|
|
|
|
follow-limit(u32),
|
|
|
|
/// All redirects from the server will be followed.
|
|
|
|
follow-all,
|
|
|
|
}
|
|
|
|
|
2024-07-01 20:58:00 +00:00
|
|
|
/// An HTTP response.
|
|
|
|
record http-response {
|
2024-08-12 14:36:49 +00:00
|
|
|
/// The response headers.
|
|
|
|
headers: list<tuple<string, string>>,
|
2024-07-01 20:58:00 +00:00
|
|
|
/// The response body.
|
2024-08-12 14:36:49 +00:00
|
|
|
body: list<u8>,
|
2024-07-01 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Performs an HTTP request and returns the response.
|
|
|
|
fetch: func(req: http-request) -> result<http-response, string>;
|
2024-08-12 14:36:49 +00:00
|
|
|
|
|
|
|
/// An HTTP response stream.
|
|
|
|
resource http-response-stream {
|
|
|
|
/// Retrieves the next chunk of data from the response stream.
|
2024-08-13 14:40:21 +00:00
|
|
|
///
|
|
|
|
/// Returns `Ok(None)` if the stream has ended.
|
2024-08-12 14:36:49 +00:00
|
|
|
next-chunk: func() -> result<option<list<u8>>, string>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Performs an HTTP request and returns a response stream.
|
|
|
|
fetch-stream: func(req: http-request) -> result<http-response-stream, string>;
|
2024-07-01 20:58:00 +00:00
|
|
|
}
|