mig-0.2.1.0: Build lightweight and composable servers
Safe HaskellSafe-Inferred
LanguageGHC2021

Mig.Core.Class.Url

Synopsis

Documentation

data Url Source #

Url-template type.

Constructors

Url 

Fields

Instances

Instances details
ToJSON Url Source # 
Instance details

Defined in Mig.Core.Class.Url

ToUrl Url Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Url Source #

mapUrl :: (Url -> Url) -> Url -> Url Source #

urlArity :: Int Source #

type family UrlOf a :: Type where ... Source #

Converts route type to URL function

Equations

UrlOf (Send method m a) = Url 
UrlOf (Query name value -> b) = Query name value -> UrlOf b 
UrlOf (Optional name value -> b) = Optional name value -> UrlOf b 
UrlOf (Capture name value -> b) = Capture name value -> UrlOf b 
UrlOf (QueryFlag name -> b) = QueryFlag name -> UrlOf b 
UrlOf (Header name value -> b) = UrlOf b 
UrlOf (OptionalHeader name value -> b) = UrlOf b 
UrlOf (Body media value -> b) = UrlOf b 
UrlOf (Cookie value -> b) = UrlOf b 
UrlOf (PathInfo -> b) = UrlOf b 
UrlOf (FullPathInfo -> b) = UrlOf b 
UrlOf (RawRequest -> b) = UrlOf b 
UrlOf (IsSecure -> b) = UrlOf b 
UrlOf (a, b) = (UrlOf a, UrlOf b) 
UrlOf (a, b, c) = (UrlOf a, UrlOf b, UrlOf c) 
UrlOf (a, b, c, d) = (UrlOf a, UrlOf b, UrlOf c, UrlOf d) 
UrlOf (a, b, c, d, e) = (UrlOf a, UrlOf b, UrlOf c, UrlOf d, UrlOf e) 
UrlOf (a, b, c, d, e, f) = (UrlOf a, UrlOf b, UrlOf c, UrlOf d, UrlOf e, UrlOf f) 
UrlOf (a :| b) = UrlOf a :| UrlOf b 

renderUrl :: IsString a => Url -> a Source #

Render URL to string-like value.

TODO: use Text.Builder

class ToUrl a where Source #

Converts server to safe url. We can use it to generate safe URL constructors to be used in HTML templates An example of how we can create safe URL's. Note that order of URL's should be the same as in server definition:

type GreetingRoute = Get Html
type BlogPostRoute = Optional "id" BlogPostId -> Get Html
type ListPostsRoute = Get Html

data Routes = Routes
  { greeting :: GreetingRoute
  , blogPost :: BlogPostRoute
  , listPosts :: ListPostsRoute
  }

-- URLs

data Urls = Urls
  { greeting :: UrlOf GreetingRoute
  , blogPost :: UrlOf BlogPostRoute
  , listPosts :: UrlOf ListPostsRoute
  }

{\-| Site URL's
URL's should be listed in the same order as they appear in the server
-\}
urls :: Urls
urls = Urls{..}
  where
    greeting
      :| blogPost
      :| listPosts
        toUrl (server undefined)

Methods

toUrl :: Server m -> a Source #

mapUrl :: (Url -> Url) -> a -> a Source #

urlArity :: Int Source #

Instances

Instances details
ToUrl Url Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Url Source #

mapUrl :: (Url -> Url) -> Url -> Url Source #

urlArity :: Int Source #

(ToUrl a, ToUrl b) => ToUrl (a :| b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> a :| b Source #

mapUrl :: (Url -> Url) -> (a :| b) -> a :| b Source #

urlArity :: Int Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Capture sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Capture sym a -> b Source #

mapUrl :: (Url -> Url) -> (Capture sym a -> b) -> Capture sym a -> b Source #

urlArity :: Int Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Optional sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Optional sym a -> b Source #

mapUrl :: (Url -> Url) -> (Optional sym a -> b) -> Optional sym a -> b Source #

urlArity :: Int Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Query sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Query sym a -> b Source #

mapUrl :: (Url -> Url) -> (Query sym a -> b) -> Query sym a -> b Source #

urlArity :: Int Source #

(KnownSymbol sym, ToUrl b) => ToUrl (QueryFlag sym -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> QueryFlag sym -> b Source #

mapUrl :: (Url -> Url) -> (QueryFlag sym -> b) -> QueryFlag sym -> b Source #

urlArity :: Int Source #

(ToUrl a, ToUrl b) => ToUrl (a, b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> (a, b) Source #

mapUrl :: (Url -> Url) -> (a, b) -> (a, b) Source #

urlArity :: Int Source #

(ToUrl a, ToUrl b, ToUrl c) => ToUrl (a, b, c) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> (a, b, c) Source #

mapUrl :: (Url -> Url) -> (a, b, c) -> (a, b, c) Source #

urlArity :: Int Source #

(ToUrl a, ToUrl b, ToUrl c, ToUrl d) => ToUrl (a, b, c, d) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> (a, b, c, d) Source #

mapUrl :: (Url -> Url) -> (a, b, c, d) -> (a, b, c, d) Source #

urlArity :: Int Source #