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 may look like this: the user presses a button on a page that is open in the browser, the system responds to 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. 3r33338.  
3r33338.  
An overview of five HTTP libraries for web development 3r33338.  
3r33338.  
The basis of this interaction of systems is AJAX technology, within the framework of which an instance of the object 3r321919 is used. XMLHttpRequest . 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. 3r33338.  
3r33338.  
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. 3r33338.  
3r33338.  
3r3323. Axios 3r33338.  
Library Axios designed to perform HTTP requests, 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 +. 3r33338.  
3r33338.  

▍ Strengths

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

▍ Weaknesses

3r33338.  
3r33333.  
3r33333. The library is quite difficult to use. 3r33333.  
3r33338.  
3r3323. Superagent 3r33338.  
Library Superagent , like Axios, suitable for Node.js and for modern browsers. It provides the developer with a simple and intuitive API, which is convenient to work with. 3r33338.  
3r33338.  
To execute an HTTP request using Superagent, it is enough to call the appropriate method of the object 3r-3219. request :
 
3r33338.  
3r3108. request
.get ('')
.then (res => log (res)) 3r3333351. .catch (err => log (err))
3r3114. 3r33338.  

▍ Strengths

3r33338.  
3r33333.  
3r33333. Supports plugins. 3r33333.  
3r33333. Configurable. 3r33333.  
3r33333. It has a nice interface for making HTTP requests. 3r33333.  
3r33333. Supports chaining of multiple calls for query execution. 3r33333.  
3r33333. Works in the Node.js environment and in browsers. 3r33333.  
3r33333. Supports progress indication for uploading and downloading data. 3r33333.  
3r33333. Supports chunked-transfer encoding mechanism. 3r33333.  
3r33333. Supports callbacks. 3r33333.  
3r33333. Many plugins have been developed for this library. 3r33333.  
3r33338.  

▍ Weaknesses

3r33338.  
3r33333.  
3r33333. It has a kind of API that does not adhere to any standards. 3r33333.  
3r33338.  
3r3323. Request 3r33338.  
Library Request , in comparison with the previously discussed tools, is a simplified tool for performing 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 3r3-37777 library. Request-Promise which implements a wrapper around the Request library and allows working with promises. 3r33338.  
3r33338.  

▍ Strengths

3r33338.  
3r33333.  
3r33333. An API that is easy to use. 3r33333.  
3r33338.  

▍ Weaknesses

3r33338.  
3r33333.  
3r33333. The library does not use promises. 3r33333.  
3r33338.  
3r3323. Fetch 3r33338.  
Fetch - This, unlike other tools discussed in this review, is not a library. This is a standard browser API, which is an alternative to r3r3219. XMLHttpRequest . 3r33338.  
3r33338.  


▍ Strengths

3r33338.  
3r33333.  
3r33333. Flexibility and ease of use. 3r33333.  
3r33333. The use of promises, which avoids the “hell of callbacks”. 3r33333.  
3r33333. Support all modern browsers. 3r33333.  
3r33333. Adherence to the request-response approach. 3r33333.  
3r33333. Simple and nice syntax. 3r33333.  
3r33333. Supported in React Native. 3r33333.  
3r33338.  


▍ Weaknesses

3r33338.  
3r33333.  
3r33333. Does not work in server environment. 3r33333.  
3r33333. Does not implement some of the features found in HTTP libraries, such as canceling a request. 3r33333.  
3r33333. It does not contain built-in support for default parameters, like query mode, headers, and credentials. 3r33333.  
3r33338.  
3r3323.
Supertest 3r3326.
3r33338.  
Library Supertest based on the Superagent library. It is intended for testing HTTP servers built on the basis of Node.js. Supertest gives the developer access to its own API and to the low-level API provided by the Superagent library. 3r33338.  
3r33338.  


▍ Strengths

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


▍ Weaknesses

3r33338.  
3r33333.  
3r33333. Does not work in browsers. 3r33333.  
3r33338.  
3r3323.
Results 3r3-3326.
3r33338.  
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. 3r33338.  
3r33338.  
[b] Dear readers! 3r33333. What HTTP libraries do you use? 3r33338.  
3r33338.  
3r33333. 3r33333. 3r33333. 3r33352.
3r33352.
! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33350.
3r33352.
+ 0 -

Add comment