Crate trillium_api

source ·
Expand description

This crate provides handlers for common http api behavior.

Eventually, some of this crate may move into the trillium crate, but for now it exists separately for ease of iteration. Expect more breaking changes in this crate then in the trillium crate.

Formats supported:

Currently, this crate supports receiving application/json and application/x-form-www-urlencoded by default. To disable application/x-form-www-urlencoded support, use default-features = false.

This crate currently only supports sending json responses, but may eventually add Accepts negotiation and further outbound response content types.

The ApiConnExt extension trait and ApiHandler can be used independently or in combination.

ApiHandler provides an easy way to deserialize a single type from the request body. ApiHandler does not handle serializing responses, so is best used in conjunction with the Json handler that this crate provides.

If ApiHandler encounters an error of any sort before the user-provided logic is executed, it will put an Error into the conn’s state. A default error handler is provided.

Macros

  • Construct a serde_json::Value from a JSON literal.

Structs

  • This handler provides the capacity to extract various components of a conn such as deserializing a body, and supports returning handlers that will be called on the returned conn.
  • Body extractor
  • a struct that halts the Conn handler sequence. see [Conn::halt] for more.
  • A newtype wrapper struct for any serde::Serialize type. Note that this currently must own the serializable type. Body extractor
  • State extractor

Enums

  • A serde-serializable error
  • Represents any valid JSON value.

Traits

  • Extension trait that adds api methods to [trillium::Conn]
  • A trait to extract content from [Conn]s to be used as the second argument to an api handler. Implement this for your types.

Functions

  • constructs a new [ApiFromConnHandler] from the provided async fn(&mut conn, FromConn) -> impl Handler