tsweb-0.1.2: An API binding Web.Spock to Database.Beam

Safe HaskellNone
LanguageHaskell2010

TsWeb.Action

Description

Various functions for reading data from the current Spock Action's context. Currently that's just reading URL path info and auth data.

Synopsis

Documentation

getPath :: Has l lts v => FldProxy l -> TsActionCtxT lts xs sess v Source #

Look up a tagged path in a view. If we have a route looking like

  runroute ro rw $ path #user ("users" <//> var) (get user)

then a view could access that user path with

  users <- getPath #user
  let txt = renderRoute users "bob"

showPath :: (AllHave ToHttpApiData as, Has l lts v, v ~ Path as Open) => FldProxy l -> TsActionCtxT lts vec sess (HVectElim as Text) Source #

Look up a path and render it. This returns a sort-of variadic function that can be provided with the right number of arguments in order to render a path. As with the above example, a route like this:

  runroute ro rw $ path #user ("users" <//> var) (get user)

could be rendered like this:

  usersfn <- showPath #user
  let txt = usersfn "bob"

or, more succinctly:

  txt <- ($ "bob") <$> showPath $user

getExtra :: (MonadIO m, ListContains n v xs) => ActionCtxT (Context lts xs) m v Source #

Look up data that was put into the ctxExtras part of the action's context. This is pretty bound up with type signatures and other verbosity, but if we have a database-writing view like so:

  runroute ro rw $ path #root root (dbwrite $ get index)

then that index view could be written like so:

  index :: ListContains n ReadWritePool xs => TsActionCtxT lts xs sess a
  index = do
    db :: ReadWritePool <- getExtra
    ...