mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
Http example passes roc check
This commit is contained in:
parent
4be19ed320
commit
bee6f2f833
@ -4,7 +4,7 @@ interface Http
|
||||
emptyBody,
|
||||
bytesBody,
|
||||
stringBody,
|
||||
jsonBody,
|
||||
# jsonBody,
|
||||
multiPartBody,
|
||||
stringPart,
|
||||
bytesPart,
|
||||
@ -16,9 +16,9 @@ interface Http
|
||||
imports [
|
||||
Effect,
|
||||
InternalTask,
|
||||
Json,
|
||||
# Json,
|
||||
Task.{ Task },
|
||||
Encode.{ Encoding },
|
||||
# Encode.{ Encoding },
|
||||
HttpTypes.{ Request, Header, TimeoutConfig, TrackerConfig, Part, Body, Response, Metadata, Error },
|
||||
]
|
||||
|
||||
@ -52,9 +52,9 @@ stringBody : [MimeType Str], Str -> Body
|
||||
stringBody = \mimeType, str ->
|
||||
Body mimeType (Str.toUtf8 str)
|
||||
|
||||
jsonBody : a -> Body | a has Encoding
|
||||
jsonBody = \val ->
|
||||
Body (MimeType "application/json") (Encode.toBytes val Json.format)
|
||||
# jsonBody : a -> Body | a has Encoding
|
||||
# jsonBody = \val ->
|
||||
# Body (MimeType "application/json") (Encode.toBytes val Json.format)
|
||||
|
||||
multiPartBody : List Part -> Body
|
||||
multiPartBody = \parts ->
|
||||
|
@ -1,17 +1,15 @@
|
||||
app "http-get"
|
||||
packages { pf: "cli-platform/main.roc" }
|
||||
imports [pf.Http, pf.Task, pf.Stdout]
|
||||
imports [pf.Http, pf.HttpTypes, pf.Task, pf.Stdout]
|
||||
provides [main] to pf
|
||||
|
||||
main : Task.Task {} [] [Write [Stdout], Network [Http]]
|
||||
main =
|
||||
# request : Request
|
||||
# request = { defaultRequest & url: "https://httpbin.org/get" }
|
||||
request : HttpTypes.Request
|
||||
request = { Http.defaultRequest & url: "https://httpbin.org/get" }
|
||||
|
||||
output <- Http.send request
|
||||
|> Task.onFail (\err -> err |> Http.errorToString |> Task.succeed)
|
||||
|> Task.await
|
||||
|
||||
# result <- Http.send request |> Task.await
|
||||
# output =
|
||||
# when result is
|
||||
# Ok payload -> payload
|
||||
# Err httpError -> Http.errorToString httpError
|
||||
output = "Hello"
|
||||
Stdout.line output
|
||||
|
Loading…
Reference in New Issue
Block a user