-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New version of HttpFs affects example of the book #9
Comments
I was not aware of this @mariomeyrelles and I haven't used the recent version of Thanks for the suggestion :) |
Hello @tamizhvendan I think the correct approach to use the new version of HttpFs is like this: type ApiHttpResponse =
| Ok of body : string
| Error of statusCode : int
| Exception of e : exn
/// Get request Async.
let getAsync urlStr : Async<ApiHttpResponse> =
let resp =
Request.create Get (Uri urlStr)
|> getResponse
resp
|> Alt.afterJob (fun resp ->
match resp.statusCode with
| x when x < 300 ->
resp
|> Response.readBodyAsString
|> Job.map Ok
| x -> Error resp.statusCode |> Job.result)
|> Alt.toAsync
/// Post request async, após a ajuda do @haf: https://github.com/haf/Http.fs/issues/117#event-914147149
let postAsync urlStr bodyStr : Async<ApiHttpResponse> =
let resp =
Request.create Post (Uri urlStr)
|> Request.bodyString bodyStr
|> getResponse
resp
|> Alt.afterJob (fun resp ->
// if we don't cancel the request, let's read the body in full
match resp.statusCode with
| x when x < 300 ->
resp
|> Response.readBodyAsString
|> Job.map Ok
| x -> Error resp.statusCode |> Job.result)
|> Alt.toAsync |
Thanks, @mariomeyrelles. I will update this in the next update of the book. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good morning Tamizhvendan,
I have been following the examples of the book and thinks have changed a little bit since the edition of the book. Now, HttpFs using Hopac.dll to do its inner workings. This change impacts a little bit on how to make things work. Now there are more abstractions to consider like "Alt", "Job" and so on.
I changed a little bit your example of get request async in order to make thinks work again. In fact, it works but I'm not sure if this is the best way:
Do you agree? Do you have a better solution?
Kind regards from Brazil.
The text was updated successfully, but these errors were encountered: