On this page:
Session
Session.close
Session.request
Session.current
Method
Method.get
Method.post
Method.delete
Method.head
Method.options
Method.patch
Method.put
Headers
8.16.0.4

2 Sessions🔗ℹ

class

class Session():

  constructor (

    ~pool_config: pool_config :: PoolConfig = PoolConfig(),

    ~ssl_context: maybe(SSLContext) = #false,

    ~cookie_jar: maybe(CookieJar) = #false,

    ~proxies: proxies :: List.of(Proxy) = []

  )

 

method

method (session :: Session).close() :: Void

Creates a new session, which can house multiple requests with a common configuration.

A session has a pool of connections, and the pool is configured through the pool_config structor argument, which is a PoolConfig.

A session is Closeable, where closing a session via the Session.close method closes all of its associated connections and responses.

method

method (session :: Session).request(

  uri :: Bytes || String || url.URL || LiteralURL,

  ~method: method :: Method = #'get,

  ~close: close :: Any.to_boolean = #false,

  ~stream: stream :: Any.to_boolean = #false,

  ~headers: headers :: Headers = {},

  ~params: params :: List.of(url.KeyValue) = [],

  ~auth: auth :: maybe(auth.Function) = #false,         

  ~data: data :: maybe(Bytes || String || Port.Input || payload.Function) = #false,

  ~timeouts: timeouts :: Timeouts = Timeouts(),

  ~max_attempts: max_attempts :: PosInt = 3,

  ~max_redirects: max_redirects :: PosInt = 16,

  ~user_agent: user_agent :: Bytes || String = current_user_agent()

) :: Response

Sends an HTTP request. By default, a GET request is sent, but the method argument selects the type of request. The functions get, post, delete, head, options, patch, and put are the same as calling Session.request with the corresponding request type (on a Session object that is given as a ~session argument, defaulting to a fresh session).

The default session used by get, post, etc.

enumeration

enum Method:

  get

  post

  delete

  head

  options

  patch

  put

Methods recognized by Session.request.

annotation

Headers

A shorthand for Map.of(String, Bytes || String).