Last active
June 29, 2017 07:01
-
-
Save rommsen/963727ed8d1dcfd45cae5b86aa78e2b6 to your computer and use it in GitHub Desktop.
Updated Http.fs file from F# Applied to work with current version of Http.fs
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
module Http | |
open HttpFs.Client | |
open Hopac | |
open FSharp.Control.Reactive | |
type HttpResponse = | |
| Ok of string | |
| Error of int | |
let getResponseAsync url = | |
let request = | |
url | |
|> Request.createUrl Get | |
|> Request.setHeader (UserAgent "FsharpRx") | |
job { | |
let! response = | |
request |> getResponse | |
let! httpResponse = | |
// https://github.com/haf/Http.fs/blob/1222c62e24165cd6611a33e4fefb0dbe59b734f5/HttpFs.SamplePostApplication/Program.fs | |
match response.statusCode with | |
| 200 -> | |
Response.readBodyAsString response | |
|> Job.map Ok | |
| _ -> | |
response.statusCode | |
|> Error | |
|> Job.result | |
return httpResponse | |
} | |
let asyncResponseToObservable = getResponseAsync >> Job.toAsync >> Observable.ofAsync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment