-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from roc-lang/fix_issue_146
Fix issue 146
- Loading branch information
Showing
3 changed files
with
15 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
app "http-get" | ||
packages { pf: "../platform/main.roc" } | ||
imports [pf.Http, pf.Task.{ Task }, pf.Stdin, pf.Stdout] | ||
imports [pf.Http, pf.Task.{ Task }, pf.Stdout] | ||
provides [main] to pf | ||
|
||
main : Task {} I32 | ||
main = | ||
_ <- Task.await (Stdout.line "Enter a URL to fetch. It must contain a scheme like \"http://\" or \"https://\".") | ||
request = { | ||
method: Get, | ||
headers: [], | ||
url: "http://www.example.com", | ||
body: Http.emptyBody, | ||
timeout: TimeoutMilliseconds 5000, | ||
} | ||
|
||
input <- Task.await Stdin.line | ||
output <- Http.send request | ||
|> Task.onErr \err -> err | ||
|> Http.errorToString | ||
|> Task.ok | ||
|> Task.await | ||
|
||
when input is | ||
End -> | ||
Stdout.line "I received end-of-input (EOF) instead of a URL." | ||
|
||
Input url -> | ||
request = { | ||
method: Get, | ||
headers: [], | ||
url, | ||
body: Http.emptyBody, | ||
timeout: NoTimeout, | ||
} | ||
|
||
output <- Http.send request | ||
|> Task.onErr \err -> err | ||
|> Http.errorToString | ||
|> Task.ok | ||
|> Task.await | ||
|
||
Stdout.line output | ||
Stdout.line output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters