mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-01 07:45:22 +03:00
Add a jsonBody helper.
This commit is contained in:
parent
81ce8979e9
commit
39443ef90f
@ -6,6 +6,7 @@ import Json.Encode as Encode
|
||||
type Body
|
||||
= EmptyBody
|
||||
| StringBody String
|
||||
| JsonBody Encode.Value
|
||||
|
||||
|
||||
encode : Body -> Encode.Value
|
||||
@ -19,6 +20,11 @@ encode body =
|
||||
[ ( "content", Encode.string content )
|
||||
]
|
||||
|
||||
JsonBody content ->
|
||||
encodeWithType "json"
|
||||
[ ( "content", content )
|
||||
]
|
||||
|
||||
|
||||
encodeWithType typeName otherFields =
|
||||
Encode.object <|
|
||||
|
@ -61,6 +61,7 @@ and describe your use case!
|
||||
import Dict exposing (Dict)
|
||||
import Dict.Extra
|
||||
import Json.Decode.Exploration as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Pages.Internal.StaticHttpBody as Body
|
||||
import Pages.Secrets
|
||||
import Pages.StaticHttp.Request as HashRequest
|
||||
@ -82,6 +83,13 @@ 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 =
|
||||
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 =
|
||||
requestDetails.url
|
||||
|
Loading…
Reference in New Issue
Block a user