Book Image

Node Web Development - Second Edition

By : David Herron
Book Image

Node Web Development - Second Edition

By: David Herron

Overview of this book

Table of Contents (17 chapters)
Node Web Development Second Edition
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Making HTTP Client requests


The next way to mitigate computationally intensive code is to push the calculation to a backend process. To do that we'll request computations from a backend Fibonacci server, using the HTTP Client object to do so. But before we look at that, let's first talk in general about using the HTTP Client object.

Node includes an HTTP Client object useful for making HTTP requests. It has enough capability 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. Its scope focuses solely on the HTTP protocol. It's possible to build a browser emulator on top of this HTTP client, for example to build a test automation tool. The HTTP Client object can be used for any kind of HTTP request, such as calling a Representational State Transfer (REST) web service.

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