Skip to content

Commit 20a3da0

Browse files
committed
Add requestFromURI
1 parent 9a781e4 commit 20a3da0

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

docs/Node/HTTP/Client.md

+8
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ request :: forall eff. Options RequestOptions -> (Response -> Eff (http :: HTTP
101101

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

104+
#### `requestFromURI`
105+
106+
``` purescript
107+
requestFromURI :: forall eff. String -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
108+
```
109+
110+
Make a HTTP request from a URI string and response callback.
111+
104112
#### `requestAsStream`
105113

106114
``` purescript

src/Node/HTTP/Client.purs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Node.HTTP.Client
1313
, headers
1414
, auth
1515
, request
16+
, requestFromURI
1617
, requestAsStream
1718
, responseAsStream
1819
, httpVersion
@@ -83,6 +84,10 @@ foreign import requestImpl :: forall eff. Foreign -> (Response -> Eff (http :: H
8384
request :: forall eff. Options RequestOptions -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
8485
request = requestImpl <<< options
8586

87+
-- | Make a HTTP request from a URI string and response callback.
88+
requestFromURI :: forall eff. String -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
89+
requestFromURI = requestImpl <<< toForeign
90+
8691
-- | Create a writable stream from a request object.
8792
requestAsStream :: forall eff r a. Request -> Writable r (http :: HTTP | eff) a
8893
requestAsStream = unsafeCoerce

test/Main.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ main = do
1818
server <- createServer respond
1919
listen server 8080 $ void do
2020
log "Listening on port 8080."
21-
req <- Client.request (Client.hostname := "localhost" <> Client.port := 8080) \response -> void do
21+
req <- Client.requestFromURI "http://localhost:8080/" \response -> void do
2222
log "Response from GET /:"
2323
let responseStream = Client.responseAsStream response
2424
pipe responseStream stdout

0 commit comments

Comments
 (0)