Handling HTTP requests
Currently, our server application will behave in the same way, no matter what kind of HTTP request is processed. Let's extend it in such a way that it behaves more like an HTTP server, and start differentiating the incoming requests based on their type, by implementing handler functions for each type of request.
Let's create a new hello-node-http-server.js
as follows:
var http = require('http'); var port = 8180; function handleGetRequest(response) { response.writeHead(200, {'Content-Type' : 'text/plain'}); response.end('Get action was requested'); } function handlePostRequest(response) { response.writeHead(200, {'Content-Type' : 'text/plain'}); response.end('Post action was requested'); } function handlePutRequest(response) { response.writeHead(200, {'Content-Type' : 'text/plain'}); response.end('Put action was requested'); } function handleDeleteRequest(response) { response.writeHead(200, {'Content-Type' : 'text/plain'}); response.end('Delete action...