Remove unnecessary Request Parser helper.

This commit is contained in:
Dillon Kearns 2022-03-08 16:04:24 -08:00
parent d4fe62b815
commit 661c84467b
3 changed files with 3 additions and 51 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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