Skip to content

Commit

Permalink
Add requestFromURI
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Sep 28, 2015
1 parent 9a781e4 commit 20a3da0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/Node/HTTP/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ request :: forall eff. Options RequestOptions -> (Response -> Eff (http :: HTTP

Make a HTTP request using the specified options and response callback.

#### `requestFromURI`

``` purescript
requestFromURI :: forall eff. String -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
```

Make a HTTP request from a URI string and response callback.

#### `requestAsStream`

``` purescript
Expand Down
5 changes: 5 additions & 0 deletions src/Node/HTTP/Client.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Node.HTTP.Client
, headers
, auth
, request
, requestFromURI
, requestAsStream
, responseAsStream
, httpVersion
Expand Down Expand Up @@ -83,6 +84,10 @@ foreign import requestImpl :: forall eff. Foreign -> (Response -> Eff (http :: H
request :: forall eff. Options RequestOptions -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
request = requestImpl <<< options

-- | Make a HTTP request from a URI string and response callback.
requestFromURI :: forall eff. String -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
requestFromURI = requestImpl <<< toForeign

-- | Create a writable stream from a request object.
requestAsStream :: forall eff r a. Request -> Writable r (http :: HTTP | eff) a
requestAsStream = unsafeCoerce
Expand Down
2 changes: 1 addition & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ main = do
server <- createServer respond
listen server 8080 $ void do
log "Listening on port 8080."
req <- Client.request (Client.hostname := "localhost" <> Client.port := 8080) \response -> void do
req <- Client.requestFromURI "http://localhost:8080/" \response -> void do
log "Response from GET /:"
let responseStream = Client.responseAsStream response
pipe responseStream stdout
Expand Down

0 comments on commit 20a3da0

Please sign in to comment.