Responding to HTTP Requests Part 11

Опубликовано: 04 Июль 2026
на канале: MBCode
42
2

Responding to HTTP requests. When you visit a website, you usually send a request to that server so that the server will serve you what you requested, as usually in the form of a GET request. There's a lot of request methods that can be sent over to a web server and the four most popular ones you see here are the POST, GET, PUT, and DELETE. These are also known as the CRUD for create, read, update, and delete, also very common database systems. A Node.js request method, one of these is usually made or created with the http.request or the http.get method and we'll see how that's done in a minute. Then when a request method is received on the server side, it's usually passed to this request object as you see in the code below. Then through this request object, you can check the method property to check what type of request was sent over. Based on that method type, you can then process the data or process whatever you need to process in the the backend accordingly. Let's go and see how this is done in node. Back in here in the demo folder, I'm going to go into the app.js folder and I'm going to modify this code a little bit. I'm going to remove the constant, the two server here we did earlier, I don't need that anymore. We'll just use the first one and that will be responding to some type of request that will be sent over from another server. Let's change this a little bit here.