Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 40 of 50 · rust

Building a Simple Web Server

Duration: 25 minutes

Building a Simple Web Server\n\nUse the hyper crate to create an HTTP server.\n\ntoml\n[dependencies]\nhyper = { version = \"0.14\", features = [\"full\"] }\n\n\nrust\nuse hyper::{Body, Request, Response, Server};\nuse hyper::service::{make_service_fn, service_fn};\nuse std::convert::Infallible;\n\nasync fn hello(_req: Request<Body>) -> Result<Response<Body>, Infallible> {\n Ok(Response::new(Body::from(\"Hello, Rust!\")))\n}\n\n#[tokio::main]\nasync fn main() {\n let make_svc = make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(hello)) });\n let addr = \"127.0.0.1:3000\".parse().unwrap();\n let server = Server::bind(&addr).serve(make_svc);\n println!(\"Listening on http://{}\", addr);\n if let Err(e) = server.await {\n eprintln!(\"server error: {}\", e);\n }\n}\n\n

Previous: Foreign Function Interface (FFI)Next: Using Actix Web