axios-cookies
v0.0.1
Published
Axios Cookies Support
Downloads
6
Maintainers
Readme
Axios-Cookie
A Cookie support library for Axios, automatically manages cookies on request, just like request.Session
.
Documentation
See the Documentation for details.
Example
import { setupCookieJar } from 'axios-cookie'
import axios from 'axios'
// Create a Axios instance
const instance = axios.create()
// Setup CookieJar, All cookies will be stored here.
const jar = setupCookieJar(instance,<adapter?>)
// Access value in CookieJar through Key.
jar.setValue(<url>,'key','value')
jar.getValue(<url>,'key')
// Remove a key
jar.setValue(<url>,null)
// Send a Request that will include the `Cookie` header configured in CookieJar.
instance.get(<url>);
// Get the Cookie Header value for site <url>.
jar.getCookie(<url>)
// Put Set-Cookie Header into the CookieJar.
jar.setCookie(<url>,<set-cookie>)
// Import from/Export to JSON Object.
jar.toJSON()
jar.fromJSON(obj)
// Get the internal CookieJar Storage, `cookiejar` or `tough-cookie`.
jar.toRaw()
Adapters
There are currently two CookieJar stores supported by default:
- SimpleCookieJarAdapter, powered by cookiejar. [default,built-in]. Very fast and tiny, x5~x6 faster than tough-cookie. The original version has too few functions and has been modified to adapt to the new functions. Built-in features, no additional installation required.
- ToughCookieJarAdapter, powered by tough-cookie.
Slow and large, but powerful!
Need to install
tough-cookie
manually.
Test
npm run test
# or
yarn run test
# or
node --test
LICENSE
MIT License