Saving cookies between requests without manually managing the cookie jar.
import got, {createSession} from 'got';
const sessionGot = createSession();
// The cookie is saved within the cookie jar of the session
await sessionGot('http://httpbin.org/cookies/set?my_cookie=my_value');
await sessionGot('http://httpbin.org/cookies', {responseType: 'json', resolveBodyOnly: true});
//=> {cookies: {my_cookie: 'my_value'}}
// The automatically initialised cookie jar
console.log(sessionGot.cookies);
//=> {my_cookie: 'my_value'}
// The cookies only apply to the session
await got('http://httpbin.org/cookies', {responseType: 'json', resolveBodyOnly: true});
//=> {cookies: {}}
Could this also work with caching?
With current APIs:
import got from 'got';
import {CookieJar} from 'tough-cookie';
const cookieJar = new CookieJar();
await got('http://httpbin.org/cookies/set?my_cookie=my_value', {cookieJar});
await got('http://httpbin.org/cookies', {cookieJar, responseType: 'json', resolveBodyOnly: true});
//=> {cookies: {my_cookie: 'my_value'}}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too