Overview of Five HTTP Web Development Libraries

Original author: Chidume Nnamdi
  • Transfer
One of the most important tasks that a programmer has to solve when developing web projects is to organize the exchange of data between the client and server parts of such projects. It may look like this: the user presses a certain button on the page open in the browser, the system responds with a request to the server, after which the server sends the page the data it has requested. In order to display such data on the page, without reloading it, it is processed, after which the page is updated and the user receives what he needs. The basis of such a system interaction is AJAX technology, in the framework of which an instance of the object is used . In order to make it easier for programmers to work with AJAX and



XMLHttpRequestXMLHttpRequest, specialized libraries have been created that provide developers with convenient interfaces, eliminating the need to use low-level mechanisms.

The material, the translation of which we publish today, is devoted to the analysis of five popular tools for working with HTTP: Axios, Request, Superagent, Fetch and Supertest.

Axios


The Axios library for executing HTTP requests is based on promises. It is suitable for use in Node.js and browser applications. The library supports all modern browsers, including IE8 +.

▍ Strengths


  • Works in Node.js environment and in browsers.
  • Supports promises.
  • Allows you to execute and cancel requests.
  • Allows you to set the response timeout.
  • Supports protection against XSRF attacks.
  • Allows intercepting requests and responses.
  • Supports indication of data upload progress.
  • Widely used in projects based on React and Vue.

▍ Weaknesses


  • The library is quite difficult to use.

Superagent


The Superagent library , like Axios, is suitable for Node.js and modern browsers. It provides the developer with a simple and understandable API that is convenient to work with.

In order to perform an HTTP request using Superagent, just call the appropriate object method request:

request
    .get('')
    .then(res => log(res))
    .catch(err => log(err))

▍ Strengths


  • Supports plugins.
  • Configurable.
  • It has a nice interface for making HTTP requests.
  • Supports chaining multiple calls to complete queries.
  • Works in Node.js environment and in browsers.
  • Supports progress display for uploading and downloading data.
  • Supports chunked-transfer encoding mechanism.
  • Supports callbacks.
  • Many plugins have been developed for this library.

▍ Weaknesses


  • It has a kind of API that does not adhere to any standards.

Request


The Request library , in comparison with the previous tools reviewed, is a simplified tool for executing HTTP requests. When using this library, you have to write less code than when working with other libraries. It does not use promises, but if you need this feature, you can use the Request-Promise library , which implements a wrapper around the Request library and allows you to work with promises.

▍ Strengths


  • An API that is easy to use.

▍ Weaknesses


  • The library does not use promises.

Fetch


Fetch is not a library, unlike the other tools covered in this review. This is a standard browser API, which is an alternative XMLHttpRequest.

▍ Strengths


  • Flexibility and ease of use.
  • The use of promises, which avoids the “hell of callbacks”.
  • Support by all modern browsers.
  • Following the request-response approach.
  • Simple and nice syntax.
  • Supported in React Native.

▍ Weaknesses


  • Does not work in a server environment.
  • It does not implement some features available in HTTP libraries, such as canceling a request.
  • Does not contain built-in support for default parameters, such as request mode, headers, credentials.

Supertest


The Supertest library is based on the Superagent library. It is designed to test HTTP servers built on the basis of Node.js. Supertest gives developers access to their own API and the low-level API provided by the Superagent library.

▍ Strengths


  • It has a convenient API.
  • Simplifies the construction of HTTP tests.
  • It can be used in conjunction with libraries for testing projects such as Chai.js and Mocha .

▍ Weaknesses


  • Doesn't work in browsers.

Summary


In this article, we examined several popular tools for working with HTTP that are useful to JS developers who create applications that use browser technologies and Node.js platforms. When selecting a base for the HTTP subsystem of a certain project, it is recommended that you first try several tools that look suitable, and then make the final decision.

Dear readers! What HTTP libraries do you use?


Also popular now: