biscotto

Biscotto

Biscotto is a Gleam library to store and manage cookies with a jar.

Types

A cookie.

pub type Cookie {
  Cookie(
    name: String,
    value: String,
    domain: String,
    path: String,
    expires: String,
    secure: Bool,
  )
}

Constructors

  • Cookie(
      name: String,
      value: String,
      domain: String,
      path: String,
      expires: String,
      secure: Bool,
    )

A jar to store cookies.

pub type CookieJar {
  CookieJar(cookies: Dict(String, Cookie))
}

Constructors

  • CookieJar(cookies: Dict(String, Cookie))

Functions

pub fn from_response(
  jar: CookieJar,
  resp: Response(a),
) -> CookieJar

Parse cookies from a response and add them to a jar.

let jar = biscotto.init()

// Perform a request
use response <- result.try(httpc.send(req))

let jar = jar
|> biscotto.from_response(response)
pub fn get(jar: CookieJar, key: String) -> Result(Cookie, Nil)

Get a specific cookie from the jar, by its name.

let jar = biscotto.init()

// Do something with the jar

let cookie = jar |> biscotto.get("my_cookie")
pub fn init() -> CookieJar

Create a new cookie jar.

let jar = biscotto.init()
pub fn peek(jar: CookieJar) -> List(Cookie)

Get all cookies from a jar.

let jar = biscotto.init()

// Do something with the jar

let first_cookie = jar
|> biscotto.peek
|> list.first
pub fn put(
  jar: CookieJar,
  cookie: List(#(String, String)),
) -> CookieJar

Add a cookie to the jar.

let jar = biscotto.init()

let cookie = [
 #("name", "value"),
 #("domain", "example.com"),
 #("path", "/")
]

let jar = biscotto.put(jar, cookie)
pub fn remove(jar: CookieJar, key: String) -> CookieJar

Remove a cookie from the jar.

let jar = biscotto.init()

let jar = biscotto.remove(jar, "my_cookie")

let assert Error(_) = jar |> biscotto.get("my_cookie")
pub fn with_cookies(
  req: Request(a),
  jar: CookieJar,
) -> Request(a)

Add cookies to a request.

let jar = biscotto.init()

let assert Ok(req) = request.to("https://example.com")

let req = biscotto.with_cookies(req, jar)
Search Document