From a8e10c353817d1744000cbdd20f6b87b739b103e Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Fri, 7 Jan 2022 15:35:31 +0100 Subject: [PATCH] Updated session docs --- Guide/session.markdown | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Guide/session.markdown b/Guide/session.markdown index b56073a06..4274b0886 100644 --- a/Guide/session.markdown +++ b/Guide/session.markdown @@ -23,7 +23,14 @@ action SessionExampleAction = do setSession "userEmail" "hi@digitallyinduced.com" ``` -Right now, [`setSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:setSession) only accepts `Text` values. Other types like `Int` have to be converted to `Text` using [`tshow theIntValue`](https://ihp.digitallyinduced.com/api-docs/IHP-Prelude.html#v:tshow). +You can use [`setSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:setSession) with other data types like `Int`, `Bool` or `UUID` as well: + + +```haskell +action SessionExampleAction = do + let meaningOfLife :: Int = 42 + setSession "meaningOfLife" meaningOfLife +``` ### Reading @@ -31,17 +38,17 @@ You can use [`getSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Control ```haskell action SessionExampleAction = do - userEmail <- getSession "userEmail" + userEmail :: Maybe Text <- getSession "userEmail" ``` `userEmail` is set to `Just "hi@digitallyinduced.com"` when the value has been set before. Otherwise, it will be `Nothing`. -For convenience you can use [`getSessionInt`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSessionInt) to retrieve the value as a `Maybe Int`, and [`getSessionUUID`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSessionUUID) to retrieve the value as a `Maybe UUID`: +The [`getSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSession) also supports other data types like `Int`, `Bool` or `UUID`: ```haskell action SessionExampleAction = do - counter :: Maybe Int <- getSessionInt "counter" - userId :: Maybe UUID <- getSessionUUID "userId" + counter :: Maybe Int <- getSession "counter" + userId :: Maybe UUID <- getSession "userId" ``` ### Deleting