Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed Jan 31, 2021
1 parent 015b073 commit e6849cb
Showing 1 changed file with 62 additions and 15 deletions.
77 changes: 62 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
# deno-another-cookiejar

This is just a very simple cookiejar for using with deno's fetch.
This library offers a fetch wrapper that retain cookies. This library also provides a simple cookiejar;

Why the name ? because I didn't want to reserve the cookiejar name, since this library may not be good at it.
Why the name ? because I didn't want to reserve the cookiejar name, since this library may not be good at it. (But I hope you like it)

## usage

you can import `Cookie`, `CookieJar` from `mod.ts` file.
you can import `Cookie`, `CookieJar`, `wrapFetch` from `mod.ts` file.

```js
export { Cookie, CookieJar, wrapFetch} from 'https://deno.land/x/[email protected]/mod.ts';
```

### wrapFetch

```js
// this simple
const fetch = wrapFetch();
```

Or

```js
// you can also pass your own cookiejar to wrapFetch to save/load your cookies
const cookieJar = new CookieJar();
// Now use this fetch and any cookie that is set will be sent with your next requests automatically
const fetch = wrapFetch({ cookieJar });
//...
fetch("http://example.com");
// and you can read your cookies from the jar
cookieJar.getCookie({
name: 'cookieName',
})?.value // your cookie value
```
You can play around with it too see what it has to offer!
cookies should only be sent to their corresponding domains automatically.
Secure cookies will not be sent over unsecure connections.
### Cookie
Expand All @@ -22,7 +54,7 @@ const cookie = new Cookie({
```js
// second:
const cooke = Cookie.from('foo=bar;'); // any string from Set-Cookie header value is also valid.
const cookie = Cookie.from('foo=bar;'); // any string from Set-Cookie header value is also valid.
```
### CookieJar
Expand All @@ -34,23 +66,14 @@ const cookieJar = new CookieJar();
also if you have cookies from before:
```js
const cookieJar = new CookieJar(cookiesArray); // cookiesArray: Array<Cookie>
```


### with fetch in ts

```js
// todo
const cookieJar = new CookieJar(cookiesArray); // cookiesArray: Array<Cookie> | Array<CookieOptions>
```
### JSON serializing cookies
### JSON serializing `Cookie`
Each cookie object is easily serialized and deserialized. Example:
```js
import { Cookie } from '...'

const exampleOption = { name: 'foo' , value: 'bar' };

const myCookie = new Cookie(exampleOption);
Expand All @@ -63,6 +86,30 @@ new Cookie (

```
### JSON serializing `CookieJar`
You can even easily serialize your `CookierJar`. Example:
```js
const exampleOption = { name: 'foo' , value: 'bar' };

const myCookie = new Cookie(exampleOption);

const cookieJar = new CookieJar([myCookie]);

new CookieJar (
JSON.parse(
JSON.stringify(cookieJar)
)
).cookies[0].toString() === myCookie.toString(); // true
```
## test
fetch wrapper tests require network access to emulate server.
run with `deno test --allow-net`
## notes
This library is only tested lightly. you can contribute to this if you want to make it better, but I probably won't add much feature/test anymore.
Expand Down

0 comments on commit e6849cb

Please sign in to comment.