Skip to main content

Crate crux_http

Crate crux_http 

Source
Expand description

A HTTP client for use with Crux

crux_http allows Crux apps to make HTTP requests by asking the Shell to perform them.

This is still work in progress and large parts of HTTP are not yet supported.

§Errors and rejections

A request resolves to a Result<Response<T>>, and a 4xx or 5xx response is on the Err side of it: crux_http turns those into HttpError::Http — headers and body included — before the event reaches the app, so Response::status is never an error status. Read the server’s own explanation of a rejection with HttpError::body or HttpError::body_json, and whatever policy it put in the headers (Retry-After, WWW-Authenticate) with HttpError::header. Response documents the shape to write, and testing the two values a test should build.

HttpError::Http means a rejection and nothing else, so HttpError::code returning Some is the test for one. The crate’s own failures are separate variants — HttpError::Json, HttpError::BodyAlreadyTaken, HttpError::InvalidStatusCode — as are the shell’s (HttpError::Url, HttpError::Io, HttpError::Timeout).

Re-exports§

pub use crate::protocol::HttpRequest;
pub use crate::protocol::HttpResponse;
pub use http;
pub use mime;

Modules§

client
command
The Command based API for crux_http
middleware
Middleware types
protocol
The protocol for communicating with the shell
testing
Helpers for testing apps that use crux_http.

Structs§

Body
An in-memory HTTP request body with an optional MIME type.
Config
Configuration for crux_http::Https and their underlying HTTP client.
Http
Method
The Request Method (VERB)
RawResponse
An in-memory HTTP response as returned by the shell, used in the middleware chain.
Request
An HTTP request, returns a Response.
RequestBuilder
Request Builder
Response
An HTTP Response that will be passed to an app’s update function.
Url
A parsed URL record.

Enums§

HttpError
An error produced when an HTTP request fails.

Type Aliases§

Result