-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
3,017 additions
and
2,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import Distribution.Simple | ||
|
||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import Distribution.Simple | ||
|
||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module Web.Spock.Api.Server | ||
( defEndpoint ) | ||
where | ||
|
||
import Web.Spock.Api | ||
import Web.Spock.Core | ||
module Web.Spock.Api.Server (defEndpoint) where | ||
|
||
import Control.Monad.Trans | ||
import Data.HVect | ||
import qualified Data.HVect as HV | ||
import Web.Spock.Api | ||
import Web.Spock.Core | ||
|
||
-- | Wire an 'Endpoint' defined using the @Spock-api@ package | ||
defEndpoint :: | ||
forall p i o m ctx. | ||
(MonadIO m, HasRep p) | ||
=> Endpoint p i o | ||
-> HVectElim p (HVectElim (MaybeToList i) (ActionCtxT ctx m o)) | ||
-> SpockCtxT ctx m () | ||
forall p i o m ctx. | ||
(MonadIO m, HasRep p) => | ||
Endpoint p i o -> | ||
HVectElim p (HVectElim (MaybeToList i) (ActionCtxT ctx m o)) -> | ||
SpockCtxT ctx m () | ||
defEndpoint ep handler = | ||
defEndpointCore (ep, step2) | ||
where | ||
step1 :: HVect p -> HVectElim (MaybeToList i) (ActionCtxT ctx m o) | ||
step1 = HV.uncurry handler | ||
defEndpointCore (ep, step2) | ||
where | ||
step1 :: HVect p -> HVectElim (MaybeToList i) (ActionCtxT ctx m o) | ||
step1 = HV.uncurry handler | ||
|
||
step2 :: HVect p -> HVect (MaybeToList i) -> ActionCtxT ctx m o | ||
step2 p = HV.uncurry (step1 p) | ||
step2 :: HVect p -> HVect (MaybeToList i) -> ActionCtxT ctx m o | ||
step2 p = HV.uncurry (step1 p) | ||
|
||
defEndpointCore :: | ||
forall p i o m ctx. | ||
(MonadIO m, HasRep p) | ||
=> (Endpoint p i o, HVect p -> HVect (MaybeToList i) -> ActionCtxT ctx m o) | ||
-> SpockCtxT ctx m () | ||
forall p i o m ctx. | ||
(MonadIO m, HasRep p) => | ||
(Endpoint p i o, HVect p -> HVect (MaybeToList i) -> ActionCtxT ctx m o) -> | ||
SpockCtxT ctx m () | ||
defEndpointCore t = | ||
case t of | ||
(MethodGet path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do r <- handler args HNil | ||
json r | ||
in get path (HV.curry pf) | ||
(MethodPost _ path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do req <- jsonBody' | ||
r <- handler args (req :&: HNil) | ||
json r | ||
in post path (HV.curry pf) | ||
(MethodPut _ path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do req <- jsonBody' | ||
r <- handler args (req :&: HNil) | ||
json r | ||
in put path (HV.curry pf) | ||
case t of | ||
(MethodGet path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do | ||
r <- handler args HNil | ||
json r | ||
in get path (HV.curry pf) | ||
(MethodPost _ path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do | ||
req <- jsonBody' | ||
r <- handler args (req :&: HNil) | ||
json r | ||
in post path (HV.curry pf) | ||
(MethodPut _ path, handler) -> | ||
let pf :: HVect p -> ActionCtxT ctx m () | ||
pf args = | ||
do | ||
req <- jsonBody' | ||
r <- handler args (req :&: HNil) | ||
json r | ||
in put path (HV.curry pf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import Distribution.Simple | ||
|
||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import Distribution.Simple | ||
|
||
main = defaultMain |
Oops, something went wrong.