about summary refs log tree commit diff
path: root/src/API.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-29T13·14+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-29T13·14+0100
commitc4a090e55803864c21e8c40432ca17772247ca8e (patch)
tree3085b8e1f323830ad0b62bbae93fb27b24729046 /src/API.hs
parent9f70cb2c612212e218b5df75c9afba08f51d3acb (diff)
Support reading / writing cookies in API
Update my API type and handler types to reflect which handlers read and write
cookies.

TODO:
- Actually read from and write to Set-Cookie header
- Returning `pure NoContent` breaks my types, so I'm returning `undefined` now
Diffstat (limited to 'src/API.hs')
-rw-r--r--src/API.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/API.hs b/src/API.hs
index c84da5aef917..50263bb3e69c 100644
--- a/src/API.hs
+++ b/src/API.hs
@@ -5,10 +5,14 @@ module API where
 --------------------------------------------------------------------------------
 import Data.Text
 import Servant.API
+import Web.Cookie
 
 import qualified Types as T
 --------------------------------------------------------------------------------
 
+-- | Once authenticated, users receive a SessionCookie.
+type SessionCookie = Header' '[Required] "Set-Cookie" T.SessionCookie
+
 type API =
       -- accounts: Create
            "accounts"
@@ -18,20 +22,24 @@ type API =
       -- accounts: Update
       -- accounts: Delete
       :<|> "accounts"
+           :> SessionCookie
            :> QueryParam' '[Required] "username" Text
            :> Delete '[JSON] NoContent
       -- accounts: List
       :<|> "accounts"
+           :> SessionCookie
            :> Get '[JSON] [T.User]
 
       -- trips: Create
       :<|> "trips"
+           :> SessionCookie
            :> ReqBody '[JSON] T.Trip
            :> Post '[JSON] NoContent
       -- trips: Read
       -- trips: Update
       -- trips: Delete
       :<|> "trips"
+           :> SessionCookie
            :> ReqBody '[JSON] T.TripPK
            :> Delete '[JSON] NoContent
       -- trips: List
@@ -41,4 +49,7 @@ type API =
       -- Miscellaneous
       :<|> "login"
            :> ReqBody '[JSON] T.AccountCredentials
-           :> Post '[JSON] NoContent
+           :> Post '[JSON] (Headers '[Header "Set-Cookie" SetCookie] NoContent)
+      :<|> "logout"
+           :> SessionCookie
+           :> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] NoContent)