Tide v0.6.0 Release Notes

Release Date: 2020-01-30 // over 4 years ago
  • ๐Ÿ“š API Documentation

    This patch introduces a new cookies API, based on the excellent ๐Ÿ“„ cookie crate. Working with cookies is a staple for ๐ŸŒ any web server, and Tide's new API now makes this entirely declarative.

    โž• Additionally we've added back CORS support. This makes it possible for ๐Ÿ”ง possible to configure the single-origin policy of browsers, which is an incredibly valuable resource.

    ๐Ÿ— And finally nesting services with Tide has become even easier. Building on the APIs in 0.5.0, the manual song-and-dance required to nest APIs is no longer required, and services can now be nested as-is through the Route::nest API.

    Examples

    Cookies

    use cookie::Cookie;
    use tide::Response;
    
    let mut app = tide::new();
    
    app.at("/").get(|req| async move {
        println!("cat snack: {:?}", req.cookie("snack"));
        Response::new(200)
    });
    app.at("/set").get(|req| async move {
        let mut res = Response::new(200);
        res.set_cookie(Cookie::new("snack", "tuna"));
        res
    });
    app.listen("127.0.0.1:8080").await?;
    

    CORS

    ๐ŸŒ Make GET, POST, and OPTIONS endpoints on this server accessible from any web page.

    use http::header::HeaderValue;
    use tide::middleware::{Cors, Origin};
    
    let rules = Cors::new()
        .allow_methods(HeaderValue::from_static("GET, POST, OPTIONS"))
        .allow_origin(Origin::from("*"))
        .allow_credentials(false);
    
    let mut app = tide::new();
    app.middleware(rules);
    app.at("/").post(|_| async { Response::new(200) });
    app.listen("localhost:8080").await?;
    

    Nesting

    Nest the inner serve inside the outer service, exposing GET /cat/nori.

    let mut inner = tide::new();
    inner.at("/nori").get(|_| async { Response::new(200) });
    
    let mut outer = tide::new();
    outer.at("/cat").nest(inner);
    
    outer.listen("localhost:8080").await?;
    

    โž• Added

    • โž• Added Route::all to match all HTTP methods on a route (#379)
    • โž• Added Route::nest to nest instances of tide::Server on sub-routes (#379)
    • โž• Added a new cors submodule containing CORS control middleware (#373)
    • โž• Added Request::cookie to get a cookie sent by the client (#380)
    • โž• Added Response::set_cookie to instruct the client to set a cookie (#380)
    • โž• Added Response::remove_cookie to instruct the client to unset a cookie (#380)

    ๐Ÿ”„ Changed

    • ๐Ÿ”„ Changed the behavior of optional params in Request.query to be more intuitive (384)
    • ๐Ÿ‘Œ Improved the debugging experience of query deserialization errors (384)
    • โšก๏ธ Updated the GraphQL example to use the latest version of Juniper (#372)
    • ๐Ÿ–จ Tide no longer prints to stdout when started (387)

    ๐Ÿ›  Fixed

    • ๐Ÿ›  Fixed an incorrect MIME type definition on Response::body (378)