Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-k committed Nov 11, 2023
1 parent 3621161 commit f7258d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/src/03-response-anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ setStatus :: IsResp a => Status -> a -> a
Although we rarely need this function as `ok` sets the right status
for successful response and all functions that need the status take it as argument.

Also we have functions to set cookies that are form url-encoded:

```haskell
setCookie :: (ToForm val, IsResp a) => SetCookie val -> a -> a

-- sets cookie params
data SetCookie

-- | Cookie setter with default params (only value)
defCookie :: val -> SetCookie val
defCookie = ...
```

For great explanation on how cookies work in HTTP you can read [an article](https://web.archive.org/web/20170122122852/https://www.nczonline.net/blog/2009/05/05/http-cookies-explained/).
Under the hood it is just a http-header with name `SetCookie`.
To read the cookie value use input request `newtype`-wrapper `Cookie`.

### How it works with server definition

How can we use both of the types as responses: `Resp` and `RespOr`?
Expand Down
15 changes: 15 additions & 0 deletions docs/src/09-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ class IsResp a where

setHeader :: (IsResp a, ToHttpApiData h) => HeaderName -> h -> a -> a

-- | Set cookie as http header from form url encoded value
setCookie :: (ToForm cookie, IsResp resp) => SetCookie cookie -> resp -> resp

data SetCookie a = SetCookie
{ cookie :: a
, expires :: Maybe UTCTime
, domain :: Maybe Text
, path :: Maybe Text
, secure :: Bool
, httpOnly :: Bool
}

-- | Default cookie which sets only the cookie itself.
defCookie :: a -> SetCookie a

-- | Bad request. The @bad@ response with 400 status.
badReq :: (IsResp a) => RespError a -> a

Expand Down

0 comments on commit f7258d5

Please sign in to comment.