O'Reilly logo

Node Web Development by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making HTTP Client requests

Now that we've looked deeply at the HTTP server object, let's jump over to the other end of the wire. Node includes an HTTP Client object useful for making HTTP requests. It's enough to issue any kind of HTTP request, but for example it does not emulate a full browser so don't get delusions of this being a full scale test automation tool. With it you can build browser emulators or any other sort of HTTP client. For example, any REST web service can be called through an HTTP client object.

Let's start with some code inspired by the wget or curl commands to make HTTP requests and show the results. Create a file named wget.js containing this code:

var http = require('http'); var url = require('url'); var util = require('util'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required