Learn how to debug a http request!
In this video I'm going to show you how to debug a HTTP server by making a request. You won't actually learn anything new in this video - we've already learned all the key features of the debugger already, but this just shows a practical use for them especially if you're not so familiar with it yet and you just want some extra guidance on how to perform specific requests.
So in a moment I'm going to set you an exercise and to do that we're going to be using this code here which will be available to you on GitHub but before I set that I wanted to show you how to use the debugger on this, or how I do it at least.
So if I run this program here I've got a very very basic HTTP server that allows you to make a post request to create to-dos. And if we jump to Postman here you can see if I make a request to it it replies back with a to-do that I've created. So it looks like it was all working there but there are some issues with this. So in the exercise you're gonna have to figure out how to debug this.
So let me just show you how quickly how to do that, at least how I like to do it. So typically what I will do is I'll either set a breakpoint on the handle func or typically what I'll do is if I know the handle func is going to hit this server.create2do function I'll just set a breakpoint here and pretty much anywhere in the function towards the top is best.
And then if I run this with debug you'll see it actually starts the server absolutely fine. As you see it says down here, the server is now running on port 8080, but the program hasn't paused. This isn't a mistake, this is meant to happen. Now what will happen is I'm going to make a request to that server, and now the debugger takes effect.
So you can see the program's now paused on this line here, and I can step over it like anything else. And if I go into Postman, you'll see the request is still hanging. If I accelerate this to the end by using this function here, which is resume program, I'll jump back to postman and you'll see the response is concluded.
Otherwise I could step through that as long as I wanted and inspect the values and stuff like that. So this is actually a really useful way to not only debug a HTTP server, but also to build them. Like sometimes I'll implement a little bit of logic and I'll debug through it just to make sure everything's happening as I expect. And you can change the values and test it that way too.
So hopefully this was helpful. Good luck with the exercise!