Add PathParam pattern for Matchpoint

This commit is contained in:
Rashad Gover 2023-04-20 18:01:18 +00:00
parent fbb4a75c21
commit 9848faf3c7

View File

@ -2,6 +2,7 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
module Okapi.Matchpoint where
@ -12,10 +13,16 @@ import Data.Text qualified as Text
import Network.HTTP.Types qualified as HTTP
import Network.Wai qualified as WAI
import Okapi.Request (Request)
import Web.HttpApiData qualified as Web
pattern Matchpoint :: HTTP.StdMethod -> [Text.Text] -> HTTP.Query -> LBS.ByteString -> HTTP.RequestHeaders -> Request
pattern Matchpoint method path query body headers <- (method, path, query, body, headers)
pattern PathParam :: (Web.ToHttpApiData a, Web.FromHttpApiData a) => a -> Text.Text
pattern PathParam p <- (Web.parseUrlPieceMaybe -> Just p)
where
PathParam p = Web.toUrlPiece p
type Server m = Monad m => Request -> m Response
data Response = Response