mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 23:12:22 +03:00
Add expectQueryParam helper.
This commit is contained in:
parent
2934da1958
commit
8800c8a16f
@ -5,7 +5,7 @@ module Server.Request exposing
|
||||
, requestTime, optionalHeader, expectContentType, expectJsonBody
|
||||
, acceptMethod, acceptContentTypes
|
||||
, map, map2, oneOf, andMap, andThen
|
||||
, expectQueryParam
|
||||
, queryParam, expectQueryParam
|
||||
, cookie, expectCookie
|
||||
, expectHeader
|
||||
, File, expectMultiPartFormPost
|
||||
@ -39,7 +39,7 @@ module Server.Request exposing
|
||||
|
||||
## Query Parameters
|
||||
|
||||
@docs expectQueryParam
|
||||
@docs queryParam, expectQueryParam
|
||||
|
||||
|
||||
## Cookies
|
||||
@ -688,6 +688,29 @@ expectQueryParam name =
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
queryParam : String -> Parser (Maybe String)
|
||||
queryParam name =
|
||||
rawUrl
|
||||
|> andThen
|
||||
(\url_ ->
|
||||
url_
|
||||
|> Url.fromString
|
||||
|> Maybe.andThen .query
|
||||
|> Maybe.andThen (findFirstQueryParam name)
|
||||
|> succeed
|
||||
)
|
||||
|
||||
|
||||
findFirstQueryParam : String -> String -> Maybe String
|
||||
findFirstQueryParam name queryString =
|
||||
queryString
|
||||
|> QueryParams.fromString
|
||||
|> QueryParams.toDict
|
||||
|> Dict.get name
|
||||
|> Maybe.andThen List.head
|
||||
|
||||
|
||||
{-| -}
|
||||
queryParams : Parser (Dict String (List String))
|
||||
queryParams =
|
||||
|
Loading…
Reference in New Issue
Block a user