mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Remove unnecessary Request Parser helper.
This commit is contained in:
parent
d4fe62b815
commit
661c84467b
@ -28,39 +28,10 @@ routes getStaticRoutes htmlToString =
|
||||
, logout
|
||||
, greet
|
||||
, fileLength
|
||||
, jsonError
|
||||
, DataSource.succeed manifest |> Manifest.generator Site.canonicalUrl
|
||||
]
|
||||
|
||||
|
||||
jsonError : ApiRoute ApiRoute.Response
|
||||
jsonError =
|
||||
ApiRoute.succeed
|
||||
(Server.Request.oneOf
|
||||
[ Server.Request.jsonBodyResult (Json.Decode.field "name" Json.Decode.string)
|
||||
|> Server.Request.map
|
||||
(\result ->
|
||||
case result of
|
||||
Ok firstName ->
|
||||
Server.Response.plainText
|
||||
("Hello " ++ firstName)
|
||||
|
||||
Err decodeError ->
|
||||
decodeError
|
||||
|> Json.Decode.errorToString
|
||||
|> Server.Response.plainText
|
||||
|> Server.Response.withStatusCode 400
|
||||
)
|
||||
, Server.Request.succeed (Server.Response.plainText "Hello anonymous!")
|
||||
]
|
||||
|> Server.Request.map DataSource.succeed
|
||||
)
|
||||
|> ApiRoute.literal "api"
|
||||
|> ApiRoute.slash
|
||||
|> ApiRoute.literal "validate-json"
|
||||
|> ApiRoute.serverRender
|
||||
|
||||
|
||||
greet : ApiRoute ApiRoute.Response
|
||||
greet =
|
||||
ApiRoute.succeed
|
||||
|
@ -3,7 +3,7 @@ module Server.Request exposing
|
||||
, method, rawBody, allCookies, rawHeaders, queryParams
|
||||
, Method(..), methodToString
|
||||
, succeed, fromResult, skip, validationError
|
||||
, requestTime, optionalHeader, expectContentType, expectJsonBody, jsonBodyResult
|
||||
, requestTime, optionalHeader, expectContentType, expectJsonBody
|
||||
, acceptMethod, acceptContentTypes
|
||||
, map, map2, oneOf, andMap, andThen
|
||||
, expectQueryParam
|
||||
@ -28,7 +28,7 @@ module Server.Request exposing
|
||||
|
||||
@docs succeed, fromResult, skip, validationError
|
||||
|
||||
@docs requestTime, optionalHeader, expectContentType, expectJsonBody, jsonBodyResult
|
||||
@docs requestTime, optionalHeader, expectContentType, expectJsonBody
|
||||
|
||||
@docs acceptMethod, acceptContentTypes
|
||||
|
||||
@ -999,25 +999,6 @@ rawBody =
|
||||
|> Parser
|
||||
|
||||
|
||||
{-| -}
|
||||
jsonBodyResult : Json.Decode.Decoder value -> Parser (Result Json.Decode.Error value)
|
||||
jsonBodyResult jsonBodyDecoder =
|
||||
map2 (\_ secondValue -> secondValue)
|
||||
(expectContentType "application/json")
|
||||
(Json.Decode.oneOf
|
||||
-- @@@ TODO use "body" instead of "jsonBody"
|
||||
[ Json.Decode.field "jsonBody" jsonBodyDecoder
|
||||
|> Json.Decode.map Ok
|
||||
|
||||
-- @@@ TODO use "body" instead of "jsonBody"
|
||||
, Json.Decode.field "jsonBody" Json.Decode.value
|
||||
|> Json.Decode.map (Json.Decode.decodeValue jsonBodyDecoder)
|
||||
]
|
||||
|> noErrors
|
||||
|> Parser
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
type Method
|
||||
= Connect
|
||||
|
Loading…
Reference in New Issue
Block a user