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.

Challenge: Building a basic API that returns a message

Challenge: Building a basic API that returns a message

(upbeat music) - [Instructor] Welcome. In this video we are going to take on a challenge where we have to build something using the standard library. So here's the challenge. We have to construct an API that responds to the endpoint slash a API with a JSON message. On the other hand, if the endpoint doesn't match, we want to return a 404 not found error. We'll be relying solely on the standard library for this. So let's harness the power of Rust without external dependencies. And the approach for this challenge would be we'll need to set up a basic HDP server, which we have seen in the past videos. Here are the steps to help you guide through this challenge. Step one is establish a TCP listener to handle incoming connections. Step two is that for each connection spawn new thread to handle it concurrently. Step three is inside the handle function. Read the client's request and determine the requested endpoint. Step four is that if the endpoint is slash API respond with a JSON message…

Contents