Add a jsonBody helper.

This commit is contained in:
Dillon Kearns 2020-01-03 14:19:35 -08:00
parent 81ce8979e9
commit 39443ef90f
2 changed files with 14 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import Json.Encode as Encode
type Body type Body
= EmptyBody = EmptyBody
| StringBody String | StringBody String
| JsonBody Encode.Value
encode : Body -> Encode.Value encode : Body -> Encode.Value
@ -19,6 +20,11 @@ encode body =
[ ( "content", Encode.string content ) [ ( "content", Encode.string content )
] ]
JsonBody content ->
encodeWithType "json"
[ ( "content", content )
]
encodeWithType typeName otherFields = encodeWithType typeName otherFields =
Encode.object <| Encode.object <|

View File

@ -61,6 +61,7 @@ and describe your use case!
import Dict exposing (Dict) import Dict exposing (Dict)
import Dict.Extra import Dict.Extra
import Json.Decode.Exploration as Decode exposing (Decoder) import Json.Decode.Exploration as Decode exposing (Decoder)
import Json.Encode as Encode
import Pages.Internal.StaticHttpBody as Body import Pages.Internal.StaticHttpBody as Body
import Pages.Secrets import Pages.Secrets
import Pages.StaticHttp.Request as HashRequest import Pages.StaticHttp.Request as HashRequest
@ -82,6 +83,13 @@ stringBody content =
Body.StringBody content Body.StringBody content
{-| Builds a JSON body for a StaticHttp request. See [elm/http's `Http.jsonBody`](https://package.elm-lang.org/packages/elm/http/latest/Http#jsonBody).
-}
jsonBody : Encode.Value -> Body
jsonBody content =
Body.JsonBody content
type alias Body = type alias Body =
Body.Body Body.Body
@ -449,14 +457,6 @@ type alias RequestDetails =
} }
--"["
-- ++ requestDetails.method
-- ++ "]"
-- ++ requestDetails.url
-- ++ String.join "," (requestDetails.headers |> List.map (\( key, value ) -> key ++ " : " ++ value))
requestToString : RequestDetails -> String requestToString : RequestDetails -> String
requestToString requestDetails = requestToString requestDetails =
requestDetails.url requestDetails.url