Tide v0.8.0 Release Notes

Release Date: 2020-04-24 // about 4 years ago
  • ๐Ÿ“š API Documentation

    ๐Ÿš€ This patch introduces the use of the ? operator in Endpoints, initial support for Server-Sent Events, static file serving, and a new submodule hierarchy. This continues the integration of http-types we started in v0.7.0

    Fallible endpoints

    Tide now allows the use of ? in endpoints. Errors are automatically converted to tide::Error and have a status code of 500 assigned to them. Overriding status codes can be done through the use of the tide::Status trait which is included in the prelude.

    use async\_std::{fs, io};use tide::{Response, StatusCode}; #[async\_std::main]async fn main() -\> io::Result\<()\> { let mut app = tide::new(); app.at("/").get(|\_| async move { let mut res = Response::new(StatusCode::Ok); res.set\_body(fs::read("my\_file").await?); Ok(res) }); app.listen("localhost:8080").await?; Ok(()) }
    

    Server-Sent Events

    ๐Ÿš€ This release makes the first steps towards integrating channels in Tide. In this release we're introducing support for Server-Sent Events, unidirectional event streams that operate over HTTP. This can be used for implementing features such as live-reloading, or sending notifications.

    use tide::sse; #[async\_std::main]async fn main() -\> Result\<(), std::io::Error\> { let mut app = tide::new(); app.at("/sse").get(sse::endpoint(|\_req, sender| async move { sender.send("fruit", "banana", None).await; sender.send("fruit", "apple", None).await; Ok(()) })); app.listen("localhost:8080").await?; Ok(()) }
    

    ๐Ÿ’ป Connecting to the stream can be done using async-sse or from the browser:

    var sse = new EventSource('/sse');sse.on("message", (ev) =\> console.log(ev));
    

    In the future we may expand on these APIs to allow other endpoints to send messages on established channels, but in order to do so we need to implement session management first.

    Static file serving

    Tide is now able to serve static directories through the Route::serve_dir method. This allows mapping URLs to directories on disk:

    #[async\_std::main]async fn main() -\> Result\<(), std::io::Error\> { let mut app = tide::new(); app.at("/public/images").serve\_dir("images/")?; app.listen("127.0.0.1:8080").await?; Ok(()) }
    

    Revamped Hierarchy

    Tide has been changing a lot recently, and we've made changes to our submodules so we can keep up. We no longer have a singular middleware submodule and instead split them up by topic. This will allow us to continue to expand on Tide's capabilities, while keeping things easy to find.

    Screenshot_2020-04-24 tide - Rust

    Future Directions

    ๐Ÿš€ The next step for us is to continue to integrate http-types into Tide, focusing on the Request, Response, and Body types. This will likely coincide with a [email protected] release. After that our goal is to expand our capabilities around file serving and testing. And finally adding support for WebSockets, sessions, and TLS.

    We're excited for the future of Tide, and we're glad you're here with us!

    โž• Added

    • Enabled the use of ? in Endpoint #438
    • HttpService is now directly implemented on Server #442
    • โž• Added Route::serve_dir which can serve full directories #415
    • โž• Added a "getting started" section to the README #445
    • โž• Added Response::redirect_permanent #435
    • โž• Added Response::redirect_temporary #435
    • โž• Added the redirect submodule #450
    • โž• Added redirect::permanent #435
    • โž• Added the log submodule providing structured logging #451
    • โž• Added a test for chunked encoding #437
    • โž• Added a logo and favicon for rustdoc #459
    • โž• Added the sse submodule providing initial Server-Sent Events support #456
    • โž• Added tide::{Body, StatusCode}, re-exported from http-types #455
    • โž• Added instructions to the README how to run examples #460
    • โž• Added an example for a nesting tide server #429

    ๐Ÿ”„ Changed

    • All Endpoints now return Result<Into<Response>> #438
    • ๐Ÿ“‡ Renamed tide::redirect to tide::redirect::temporary #450
    • 0๏ธโƒฃ Logging middleware is now enabled by default #451
    • ๐Ÿ”’ Moved CORS middleware to the security submodule #453
    • ๐Ÿ‘ Allow tide::Result<Response> to be abbreviated as tide::Result #457
    • Replaced the use of IntoResponse with Into<Response> #463

    โœ‚ Removed

    • โœ‚ Removed unused server impl code #441
    • โœ‚ Removed the tide::server::Service struct #442
    • โœ‚ Removed the tide::server submodule #442
    • โœ‚ Removed the tide::middleware submodule #453
    • โœ‚ Removed the IntoResponse trait #463

    ๐Ÿ›  Fixed

    • ๐Ÿ›  Fixed CORS behavior if there is no origin header #439
    • ๐Ÿ›  Fixed documentation formatting in lib.rs #454
    • ๐Ÿ›  Fixed a stability issue in our tests regarding by opening random ports #446