Skip to main content

A simple asynchronous reverse proxy in Rust

Getting Started with Rust
In my previous article, I had written a very simple and basic reverse proxy. It is just like Nginx but without all the usefulness. In this new code, I have used tokio.rs. Tokio provides runtimes for asynchronous programming. A runtime bundles services together and makes a single type of (for want of a better word) process, service, runtime, etc. This makes it easier to shut down, started, etc. In the code below, I have used TcpStream and TcpListener from the tokio library and not std. I have also spawned for tokio threads and within that, tokio tasks, which are sort of like green threads, but not quite because Rust does not natively support it.

A simple reverse proxy server in Rust

Why Rust
I wanted the application I write to be able to run well on a raspberry pi zero. And Rust could do all this extremely well. Apart from that, Rust is the safest language ever. And it's not like when Java says that it's secure. Rust means it and has gone above and beyond to make sure you can only write safe and secure code. It does this because it has one of the most advanced and thorough compilers, that WILL NOT compile your code unless it is safe. I choose Rust. Q.E.D.
Subscribe to Reverse Proxy
x

Work

Therefore logo
80 Atlantic Ave, Toronto, ON Canada
Email: hello@therefore.ca
Call us: +1 4166405376
Linkedin

Let us know how we can help!