DEV Community

Falah Al Fitri
Falah Al Fitri

Posted on • Edited on

NodeJS request

Request - Simplified HTTP client

Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

request

// https://www.npmjs.com/package/request
const request = require('request')

/* --- */

request( 'https://example.com', function ( error, response, body ) {

    /*
        Print the error if one occurred
    */
    console.error( `error: ${error}` )

    /*
        Print the response status code if a response was received
    */
    console.log( 'statusCode:', response && response.statusCode)

    /*
        Print the HTML for the example homepage
    */
    console.log( `body: ${body}` )

} )

Enter fullscreen mode Exit fullscreen mode

Example request


Example request callback


Example request promise


Example request promise return


Example request async/await

Top comments (0)