diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6e141e --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Email Newsletter API + +- An API to enable blog visitors subcribe to the newsletter so that they can receive updates when new content is published on the blog. + +## Development setup + +- Install [cargo-watch](https://crates.io/crates/cargo-watch). +- Open your favorite text editor (better be neovim or emacs). +- Run `cargo watch -x check -x test -x run` to lint, test and run the binary as soon as you make a change to the file. +- Bonus: install and use `mold`, a very fast linker that can link your Rust binary _blazingly fast_. + +## [Technical Write Up](./docs/technical_write_up.md) diff --git a/docs/technical_write_up.md b/docs/technical_write_up.md new file mode 100644 index 0000000..1c4d286 --- /dev/null +++ b/docs/technical_write_up.md @@ -0,0 +1,22 @@ +# Technical Write Up + +## Routes + +- `health_check`: returns a HTTP code 200 if the server is up and running. Response body is empty. + +## The `tokio` Async Runtime + +`tokio` will be the engine in charge of driving Futures to completion + +- `#[tokio::main]` macro is just a builder to help building the runtime. It is basically saying, we want this async function to be run. +- `tokio::spawn(/*async task*/)` will spawn an async task to be run. We can continue executing other code concurrently while `task` runs in the background. If we need to wait for `task` to complete before proceeding, we can use `task.await` (which `#[tokio::test]` will take care for us in the mean time). + +### Testing with `tokio` + +- Each test has to be marked `#[tokio::test]`. +- This macro will build a new async runtime for that one test. +- By calling `spawn_app()`, we will get a API HttpServer running for the entire duration of the single test that the macro above belongs to. + +## The Test Suite + +- The OS will find an available port for the test suite to use.