Extension of rest-api-handler library. It parse cookies from response headers and use them to send requests.
Library is compiled for node 9.6 and include Fetch polyfill.
Install the library:
npm install cookie-api-handler
Send requests:
const CookieApi = require('cookie-api-handler');
(async () => {
const api = new CookieApi('');
await api.get('https://endomondo.com');
console.log(api.getCookies());
})();
For more information about sending requests, check base library.
Cookies are inserted to object based on response headers. Class have methods to add custom cookies and read the current ones:
// will return object of decoded strings
api.getCookies();
// you can add custom cookies, string only. Cookies will be encoded.
api.addCookies({
cookieName: 'cookieValue',
});