Skip to content

0.4.0

Compare
Choose a tag to compare
@yoshuawuyts yoshuawuyts released this 27 Nov 21:04

This release is a further polishing of Tide's APIs, and works towards
significantly improving Tide's user experience. The biggest question left
unanswered after this patch is how we want to do error handling, but aside from
that the end-user API should be pretty close to where we want it to be.

The biggest changes in this patch is endpoints now take Request instead of
Context. The new Request and Response types are no longer type aliases but
concrete types, making them substantially easier to use. This also means that
we've been able to fold in all the Ext methods we were exposing, enabling
methods such as let values: Schema = req.body_json()?; to deserialize an
incoming JSON body through a Serde schema. This should make it significantly
easier to write APIs with Tide out of the box.

Example

Create a "hello world" app:

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    let mut app = tide::new();
    app.at("/").get(|_| async move { "Hello, world!" });
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

Redirect from /nori to /chashu:

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    let mut app = tide::new();
    app.at("/chashu").get(|_| async move { "meow" });
    app.at("/nori").get(tide::redirect("/chashu"));
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

Added

  • Added logger::RequestLogger based on log (replaces logger:RootLogger).
  • Added Request with inherent methods (replaces Context).
  • Added Server (replaces App).
  • Added Response (replacing a type alias of the same name).
  • Added a prelude submodule, holding all public traits.
  • Added a new free function, a shorthand for Server::new.
  • Added a with_state free function, a shorthand for Server::with_state.
  • Added Result type alias (replaces EndpointResult).
  • Added a redirect free function to redirect from one endpoint to another.

Changed

  • Resolved an #[allow(unused_mut)] workaround.
  • Renamed ExtractForms to ContextExt.
  • Response is now a newly defined type.

Removed

  • Removed logger::RootLogger (replaced by logger:RequestLogger).
  • Removed internal use of the box_async macro.
  • Removed Context (replaced by Request).
  • Removed the Response type alias (replaced by a new Response struct).
  • Removed App (replaced by Server).
  • Temporarily disabled the multipart family of APIs, improving compilation
    speed by ~30%.
  • Removed EndpointResult (replaced by Result).