January 2019
Intermediate to advanced
520 pages
14h 32m
English
Let's create a microservice in a new crate based on the actix-web crate.
Add the following dependencies to Cargo.toml:
[dependencies]actix = "0.7"actix-web = "0.7"askama = "0.6"chrono = "0.4"env_logger = "0.5"futures = "0.1"[build-dependencies]askama = "0.6"
We will construct a tiny server that will render an index page asynchronously with the current time, with one-minute precision. As a matter of fact, there is a shortcut function that does this:
fn now() -> String { Utc::now().to_string()}
We use the askama crate to render the template of the index page and insert the current time taken from a shared state it it. For the time value, we use a String instead of types directly from the chrono crate, in order to get a value that ...
Read now
Unlock full access