⬆️ ⬇️

An overview of five HTTP libraries for web development

One of the most important tasks that a programmer has to solve when developing web projects is the organization of data exchange between client and server parts of such projects. It might look like this: the user presses a button on a page that is open in the browser, in response, the system executes a request to the server, after which the server sends the page the requested data. In order to display such data, on the page, without reloading it, they are processed, after which the page is updated and the user gets what he needs.







The basis of this system interaction is the AJAX technology, within the framework of which an instance of the XMLHttpRequest object is used. In order to make it easier for programmers to work with AJAX and XMLHttpRequest , 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 are publishing today, is devoted to the analysis of five popular tools for working with HTTP: Axios, Request, Superagent, Fetch and Supertest.



Axios



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



▍ Strengths





▍ Weaknesses





Superagent



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



In order to execute an HTTP request using Superagent, it is enough to call the appropriate method of the request object:



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


▍ Strengths





▍ Weaknesses





Request



The Request library, in comparison with the previously discussed tools, 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 opportunity, you can use the Request-Promise library, which implements a wrapper around the Request library and allows you to work with promises.



▍ Strengths





▍ Weaknesses





Fetch



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



▍ Strengths





▍ Weaknesses





Supertest



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



▍ Strengths





▍ Weaknesses





Results



In this article, we looked at several popular HTTP tools 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 to first try out several tools that look appropriate, and then make the final decision.



Dear readers! What HTTP libraries do you use?



Source: https://habr.com/ru/post/432634/



All Articles