webgear-core-1.3.1: Composable, type-safe library to build HTTP APIs
Safe HaskellNone
LanguageHaskell2010

WebGear.Core.Trait.Cookie

Description

Traits and middlewares to handle cookies in requests and responses.

Synopsis

Traits

data Cookie (e :: Existence) (name :: Symbol) val Source #

Trait for a cookie in HTTP requests

Constructors

Cookie 

Instances

Instances details
type Absence (Cookie 'Optional name val) Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Absence (Cookie 'Required name val) Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Attribute (Cookie 'Optional name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Attribute (Cookie 'Optional name val) Request = Maybe val
type Attribute (Cookie 'Required name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Attribute (Cookie 'Required name val) Request = val
type Prerequisite (Cookie e name val) ts Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Prerequisite (Cookie e name val) ts = HasTrait (RequestHeader e 'Strict "Cookie" Text) ts

data SetCookie (e :: Existence) (name :: Symbol) Source #

Trait for a cookie in HTTP responses

Constructors

SetCookie 

Instances

Instances details
type Attribute (SetCookie 'Optional name) Response Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

type Attribute (SetCookie 'Required name) Response Source # 
Instance details

Defined in WebGear.Core.Trait.Cookie

Middlewares

cookie Source #

Arguments

:: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Required name val), HasTrait (RequestHeader 'Required 'Strict "Cookie" Text) ts) 
=> h (With Request ts, Either CookieNotFound CookieParseError) Response

Error handler

-> Middleware h ts (Cookie 'Required name val ': ts) 

Extract a cookie and convert it to a value of type val.

The associated trait attribute has type val.

Example usage:

cookie @"name" @Integer errorHandler okHandler

optionalCookie Source #

Arguments

:: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Optional name val), HasTrait (RequestHeader 'Optional 'Strict "Cookie" Text) ts) 
=> h (With Request ts, CookieParseError) Response

Error handler

-> Middleware h ts (Cookie 'Optional name val ': ts) 

Extract an optional cookie and convert it to a value of type val.

The associated trait attribute has type Maybe val; a Nothing value indicates that the cookie is missing from the request.

Example usage:

optionalCookie @"name" @Integer errorHandler okHandler

setCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Required name) => h (With Response ts, SetCookie) (With Response (SetCookie 'Required name ': ts)) Source #

Set a cookie value in a response.

Example usage:

response' <- setCookie @"name" -< (response, cookie)

setOptionalCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Optional name) => h (With Response ts, Maybe SetCookie) (With Response (SetCookie 'Optional name ': ts)) Source #

Set an optional cookie value in a response.

Setting the cookie to Nothing will remove it from the response if it was previously set. The cookie will be considered as optional in all relevant places (such as documentation).

Example usage:

response' <- setOptionalCookie @"name" -< (response, cookie)