Can we read response headers from Bluebird promise request?

15 views
Skip to first unread message

Saurabh Verma

unread,
May 28, 2020, 6:46:23 AM5/28/20
to bluebird
Using XMLHttpRequest we can do something like below to read the response headers

        let client = new XMLHttpRequest();
        client.open("POST", "{MYURL}", true);
        client.send(JSON.stringify(data));
        client.onreadystatechange = function () {
            if (this.readyState === this.HEADERS_RECEIVED) {
                console.log(client.getAllResponseHeaders().toLowerCase());
            }
        };

Can we do it somehow using Bluebird?

Дмитрий Мозговой

unread,
May 28, 2020, 7:09:00 AM5/28/20
to bluebird
Bluebird is just an implementation of Promise API, this not a request library. Use modern fetch API instead of plain XMLHttpRequest. See https://developer.mozilla.org/en-US/docs/Web/API/Response/headers and https://stackoverflow.com/questions/43344819/reading-response-headers-with-fetch-api
Then use BlueBird.resolve(fetch(...)).then(...) to convert native promise to bluebird if you needed.

четвер, 28 травня 2020 р. 13:46:23 UTC+3 користувач Saurabh Verma написав:
Reply all
Reply to author
Forward
0 new messages