Skip to content

Instantly share code, notes, and snippets.

@rommsen
Last active June 29, 2017 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rommsen/963727ed8d1dcfd45cae5b86aa78e2b6 to your computer and use it in GitHub Desktop.
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
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