Skip to content

Updates for 1.0 core libraries #5

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

Merged
merged 2 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"url": "git://github.com/purescript-node/purescript-node-http.git"
},
"devDependencies": {
"purescript-console": "^0.1.0"
"purescript-console": "^1.0.0"
},
"dependencies": {
"purescript-maps": "^0.5.4",
"purescript-options": "^0.6.0",
"purescript-unsafe-coerce": "^0.1.0",
"purescript-node-streams": "^0.4.0",
"purescript-node-url": "^0.1.1"
"purescript-maps": "^1.0.0",
"purescript-node-streams": "^1.0.0",
"purescript-node-url": "^1.0.0",
"purescript-options": "^1.0.0",
"purescript-unsafe-coerce": "^1.0.0"
}
}
4 changes: 2 additions & 2 deletions docs/Node/HTTP.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Get the request URL
#### `requestAsStream`

``` purescript
requestAsStream :: forall eff a. Request -> Readable () (http :: HTTP | eff) a
requestAsStream :: forall eff. Request -> Readable () (http :: HTTP | eff)
```

Coerce the request object into a readable stream.
Expand Down Expand Up @@ -125,7 +125,7 @@ Set the status message.
#### `responseAsStream`

``` purescript
responseAsStream :: forall eff a. Response -> Writable () (http :: HTTP | eff) a
responseAsStream :: forall eff. Response -> Writable () (http :: HTTP | eff)
```

Coerce the response object into a writable stream.
Expand Down
9 changes: 2 additions & 7 deletions docs/Node/HTTP/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ newtype RequestHeaders

A HTTP request object

##### Instances
``` purescript
instance requestHeadersIsOption :: IsOption RequestHeaders
```

#### `RequestOptions`

``` purescript
Expand Down Expand Up @@ -113,15 +108,15 @@ Make a HTTP request from a URI string and response callback.
#### `requestAsStream`

``` purescript
requestAsStream :: forall eff r a. Request -> Writable r (http :: HTTP | eff) a
requestAsStream :: forall eff r. Request -> Writable r (http :: HTTP | eff)
```

Create a writable stream from a request object.

#### `responseAsStream`

``` purescript
responseAsStream :: forall eff w a. Response -> Readable w (http :: HTTP | eff) a
responseAsStream :: forall eff w. Response -> Readable w (http :: HTTP | eff)
```

Create a readable stream from a response object.
Expand Down
20 changes: 0 additions & 20 deletions src/Node/HTTP.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

// module Node.HTTP

var http = require('http');

exports.createServer = function(handleRequest) {
Expand All @@ -24,14 +22,6 @@ exports.listen = function(server) {
};
};

exports.writeString = function(res) {
return function(s) {
return function() {
res.write(s);
};
};
};

exports.setHeader = function(res) {
return function(key) {
return function(value) {
Expand Down Expand Up @@ -67,13 +57,3 @@ exports.setStatusMessage = function(res) {
};
};
};

exports.end = function(res) {
return function(done) {
return function() {
res.end(null, function() {
done();
});
};
};
};
6 changes: 3 additions & 3 deletions src/Node/HTTP.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Node.HTTP where

import Prelude

import Data.StrMap
import Control.Monad.Eff
import Node.Stream
import Control.Monad.Eff (Eff)
import Data.StrMap (StrMap)
import Node.Stream (Writable, Readable)
import Unsafe.Coerce (unsafeCoerce)

-- | The type of a HTTP server object
Expand Down
2 changes: 0 additions & 2 deletions src/Node/HTTP/Client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

// module Node.HTTP.Client

var http = require('http');
var https = require('https');

Expand Down
5 changes: 1 addition & 4 deletions src/Node/HTTP/Client.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ module Node.HTTP.Client

import Prelude (Unit, (<<<))

import Control.Monad.Eff (Eff)
import Data.Foreign (Foreign, toForeign)
import Data.Options (Options, Option, options, opt)
import Data.StrMap (StrMap())

import Node.HTTP (HTTP())
import Node.Stream (Readable, Writable)
import Node.URL as URL

import Control.Monad.Eff (Eff)

import Unsafe.Coerce (unsafeCoerce)

-- | A HTTP request object
Expand Down
2 changes: 0 additions & 2 deletions test/Main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

// module Test.Main

exports.stdout = process.stdout;
30 changes: 17 additions & 13 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ module Test.Main where

import Prelude

import Node.Encoding (Encoding(..))
import Node.HTTP (HTTP, listen, createServer, setHeader, requestMethod, requestURL, responseAsStream, requestAsStream, setStatusCode)
import Node.Stream (Writable, end, pipe, writeString)
import Node.HTTP.Client as Client
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Foldable (foldMap)
import Data.Options

import Control.Monad.Eff.Console

import Node.HTTP
import qualified Node.HTTP.Client as Client
import Node.Stream
import Node.Encoding
import Partial.Unsafe (unsafeCrashWith)

foreign import stdout :: forall eff r. Writable r eff

main :: forall eff. Eff (console :: CONSOLE, http :: HTTP | eff) Unit
main = do
testBasic
testHttps

testBasic :: forall eff. Eff (console :: CONSOLE, http :: HTTP | eff) Unit
testBasic = do
server <- createServer respond
listen server 8080 $ void do
Expand All @@ -31,24 +32,27 @@ testBasic = do
log (requestMethod req <> " " <> requestURL req)
case requestMethod req of
"GET" -> do
let html = foldMap (<> "\n")
let html = foldMap (_ <> "\n")
[ "<form method='POST' action='/'>"
, " <input name='text' type='text'>"
, " <input type='submit'>"
, "</form>"
]
setHeader res "Content-Type" "text/html"
writeString outputStream UTF8 html(return unit)
end outputStream (return unit)
writeString outputStream UTF8 html (pure unit)
end outputStream (pure unit)
"POST" -> void $ pipe inputStream outputStream
_ -> unsafeCrashWith "Unexpected HTTP method"

testHttps :: forall eff. Eff (console :: CONSOLE, http :: HTTP | eff) Unit
testHttps =
simpleReq "https://api.github.com"
simpleReq "https://pursuit.purescript.org/packages/purescript-node-http/badge"

simpleReq :: forall eff. String -> Eff (console :: CONSOLE, http :: HTTP | eff) Unit
simpleReq uri = do
log ("GET " <> uri <> ":")
req <- Client.requestFromURI uri \response -> void do
log "Response:"
let responseStream = Client.responseAsStream response
pipe responseStream stdout
end (Client.requestAsStream req) (return unit)
end (Client.requestAsStream req) (pure unit)