Tide v0.9.0 Release Notes

Release Date: 2020-05-23 // almost 4 years ago
  • โšก๏ธ This patch updates http-types to 2.0.0, removes http-service in favor of
    Server::respond, and adds an all-new Redirect struct.

    http-types 2.0

    ๐Ÿš€ Read the http-types changelog for a full rundown of changes. But the biggest change for Tide is that working with headers in Tide is becoming a lot easier. To see all the changes in action, compare what it was like to compare a header with how it is now:

    // http-types 1.xassert\_eq!(req.header(&"X-Forwarded-For".parse().unwrap()), Some(&vec!["127.0.0.1".parse().unwrap()]));// http-types 2.xassert\_eq!(req.header["X-Forwarded-For"], "127.0.0.1");
    

    Constructing headers from string literals, comparing to string literals,
    using [] to access by name โ€” this should make it much easier to work with
    Tide!

    Server::respond

    http-service has been a tricky one. It originally served as a simplified wrapper around hyperium/hyper with a streaming Body type with the potential to abstract to other backends as well. But as we've evolved Tide and the http-rs ecosystem, we found http-service becoming more a hurdle than a help.

    โœ… In this patch we're removing http-service from Tide and introducing Server::respond as its replacement. This not only makes Tide easier to maintain, it makes it easier to use with any other backend than ever before. It also provides convenient way to unit test Tide apps as well:

    use tide::http::{self, Url, Method}; #[async\_std::test]async fn hello\_world() -\> tide::Result\<()\> { let mut app = tide::new(); app.at("/").get(|\_| async move { Ok("hello world")} ); let req = http::Request(Method::Get, Url::parse("http://computer.soup")?); let res = app.respond(req).await?; assert\_eq!(res.body\_string().await?, "hello world".to\_owned()); Ok(()) }
    

    Redirect

    In the past we introduced the redirect submodule which provided redirect endpoints. And Response::redirect* which provided methods to create redirects inside endpoints. In this patch we're removing those APIs in favor of tide::Redirect which can be used both to create new redirect endpoint, and be used inside existing endpoints to redirect:

    use tide::Redirect; #[async\_std::main]async fn main() -\> tide::Result\<()\> { let mut app = tide::new(); app.at("/fish").get(|\_| async move { Ok("yum") }); // Either create a redirect endpoint directly. app.at("/chashu").get(Redirect::new("/fish")); // Or redirect from inside an existing endpoint// enabling conditional redirects. app.at("/nori").get(|\_| async move { Redirect::new("/fish") }); app.listen("127.0.0.1:8080").await?; Ok(()) }
    

    Big thanks to @ethanboxx for introducing this pattern to Tide. We'll be looking to introduce this pattern to more APIs in the future.

    โž• Added

    • โž• Added Response::take_body #499
    • โž• Added Response::remove_header #508
    • โž• Added Server::respond #503
    • โž• Added @tirr-c as a co-author in Cargo.toml #507
    • โž• Added Response::from_res #466
    • โž• Added AsRef/AsMut impls to bridge Tide and http-types's req/res types #510
    • โž• Added Into<http_types::Request> for Request #510
    • โž• Added Response::header #515
    • โž• Added tide::log::start which starts a logger that pretty-prints in development and prints ndjson in release mode #495

    โœ‚ Removed

    • โœ‚ Removed http-service in favor of Server::respond #503
    • โœ‚ Removed the redirects directory in favor of tide::Redirect #513

    ๐Ÿ”„ Changed

    • Unified all redirect functionality into a single Redirect type #513
    • ๐Ÿ”Š The log middleware now logs time more accurately #517

    Internal

    • Apply clippy #526
    • โฌ†๏ธ Bump version number in README #489
    • ๐Ÿ”„ Changed file structure to match external exports #502
    • โœ‚ Remove unused dependencies #506
    • โž• Added a no-dev-deps check to CI #512
    • Fibonnacci example now uses Instant::elapsed #522