How can I build a website using only standard libraries?

Hello, I want to build a multi-page website with a contact or login page (Example of a form to get input data) Using standard offices only, Can you help me? I searched a lot and didn't find anything that helped me.

The standard library doesn't contain any http server. You will either need to write one yourself or use an existing crate. The most common one is hyper, which has multiple frameworks built on top of it.

3 Likes

Can TcpStream and TcpListener be used instead of http server?

An http server is implemented on top of TcpListener. If you don't use an existing http server, you will have to build one yourself on top of TcpListener to talk the http protocol. Especially if you want to use TLS (https) using an existing crate is pretty much unavoidable unless you are willing to put a lot of effort into implementing it yourself. (and in the case of TLS unless you know a lot about cryptography and what kind of mistakes can break it, you should use code written by someone who does know crypto)

3 Likes

Thank you, I'm new to programming.

Start from the modern version of Rust Book, it includes manual on writing your own web server from scratch:
https://doc.rust-lang.org/book/ch20-00-final-project-a-web-server.html
(the first single threaded version enough for the start).

Also, you'll need something to parse HTTP requests and form data, I myself use
https://crates.io/crates/lalrpop
arbitrary parser generator (anyway it is good to have such a tool in your skills pocket for reading any ASCII data).

Then, you maybe want to write something in gaming, data crunching, or media decoding what needs more computing power than the classical JS, so: Introduction - Rust and WebAssembly

1 Like

Thank you very useful information, but there is no way to read post data in rust book.

HTTP 1 is a plaintext protocol, with some determination you can implement a POST handler in "pure" rust with just the standard library and an understanding of the HTTP plaintext protocol. ex: RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1

If this is for fun and learning then you can go pretty far with just the Rust book, the standard library IO like TCPListener, and an understanding of the HTTP plaintext protocol.

Where you will probably run into trouble is if you want this to be on the public internet, you'll generally want to have your traffic be encrypted via HTTPS/TLS, which is not likely to be a path you want to go down.. Using a library that builds on more community libraries than just the standard ones will be the best path there.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.