From the course: Rust Web Frameworks: Build Real World Projects with Actix, Rocket, Warp, Tide, and std Library
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Building a basic API that returns a message - Rust Tutorial
From the course: Rust Web Frameworks: Build Real World Projects with Actix, Rocket, Warp, Tide, and std Library
Solution: Building a basic API that returns a message
(lively upbeat music) - [Instructor] Welcome back. In this video, we're going to check out the solution for the challenge of making a basic API using the Standard Library. Were you able to complete the challenge? Let's look at the solution and break it down. Before we look at the code of the solution, let's go through the overview of the solution. So, we'll be implementing a basic HTTP server that listens for incoming connections on port 8080 of our localhost, and we will do this with the help of two functions. The first one is the main function. In the main function, we'll create the TcpListener and start listening for incoming connections. And for each incoming connection, we spawn a new thread to handle it concurrently using std::thread spawn. The second function is the handle_client function. This function is responsible for handling each client connection. We read the client's request and check if it contains GET /api. If it does, we will respond with a JSON message, otherwise…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Introduction to the standard Rust library3m 32s
-
(Locked)
Important functions, features, and concepts3m 36s
-
(Locked)
Building a server with the std library3m 47s
-
(Locked)
Extra, helpful features in the std library3m 35s
-
(Locked)
Tokio and asynchronous programming3m 27s
-
(Locked)
Challenge: Building a basic API that returns a message1m 21s
-
(Locked)
Solution: Building a basic API that returns a message3m 49s
-
-
-
-
-
-