DEV Community

Falah Al Fitri
Falah Al Fitri

Posted on • Edited on

2 2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay