Skip to content
This repository was archived by the owner on Jul 6, 2020. It is now read-only.

Commit 7288d3d

Browse files
committed
Updates codebase for PureScript v0.11.
1 parent f7a95fb commit 7288d3d

File tree

11 files changed

+249
-47
lines changed

11 files changed

+249
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/.psc*
66
/.psa*
77
*.swp
8+
notes

bower.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "purescript-http-request",
2+
"name": "purescript-requests",
33
"description": "Make cross-platform requests from node or the browser in pure PureScript.",
44
"license": "BSD-3-Clause",
5-
"repository": {
6-
"type": "git",
7-
"url": "git://github.com/chrisdotcode/purescript-http.git"
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/chrisdotcode/purescript-requests.git"
88
},
99
"ignore": [
1010
"**/.*",
@@ -13,32 +13,32 @@
1313
"output"
1414
],
1515
"dependencies": {
16-
"purescript-prelude": "^2.1.0",
17-
"purescript-foreign": "^3.0.1",
18-
"purescript-either": "^2.1.0",
19-
"purescript-lists": "^3.2.1",
20-
"purescript-foldable-traversable": "^2.0.0",
21-
"purescript-monoid": "^2.2.0",
22-
"purescript-aff": "^2.0.2",
23-
"purescript-maps": "^2.0.2",
24-
"purescript-maybe": "^2.0.1",
25-
"purescript-datetime": "^2.0.0",
26-
"purescript-uri": "^2.0.0",
27-
"purescript-http-types": "^0.5.0",
28-
"purescript-arrays": "^3.1.0",
29-
"purescript-tuples": "^3.1.0",
30-
"purescript-strings": "^2.1.0",
31-
"purescript-control": "^2.0.0",
32-
"purescript-string-parsers": "^2.0.0",
33-
"purescript-pathy": "^3.0.2",
34-
"purescript-generics": "^3.3.0",
35-
"purescript-transformers": "^2.1.0",
36-
"purescript-exceptions": "^2.0.0",
37-
"purescript-js-date": "^3.0.0"
16+
"purescript-prelude": "^3.0.0",
17+
"purescript-foreign": "^4.0.0",
18+
"purescript-either": "^3.0.0",
19+
"purescript-lists": "^4.6.0",
20+
"purescript-foldable-traversable": "^3.3.0",
21+
"purescript-monoid": "^3.0.0",
22+
"purescript-aff": "^3.1.0",
23+
"purescript-maps": "^3.1.0",
24+
"purescript-maybe": "^3.0.0",
25+
"purescript-datetime": "^3.1.0",
26+
"purescript-uri": "^3.0.1",
27+
"purescript-http-types": "^0.6.1",
28+
"purescript-arrays": "^4.1.0",
29+
"purescript-tuples": "^4.1.0",
30+
"purescript-strings": "^3.1.0",
31+
"purescript-control": "^3.3.0",
32+
"purescript-string-parsers": "^3.0.1",
33+
"purescript-pathy": "^4.0.0",
34+
"purescript-generics": "^4.0.0",
35+
"purescript-transformers": "^3.4.0",
36+
"purescript-exceptions": "^3.0.0",
37+
"purescript-js-date": "^5.0.0"
3838
},
3939
"devDependencies": {
40-
"purescript-console": "^2.0.0",
41-
"purescript-psci-support": "^2.0.0",
42-
"purescript-debug": "^2.0.0"
40+
"purescript-console": "^3.0.0",
41+
"purescript-psci-support": "^3.0.0",
42+
"purescript-debug": "^3.0.0"
4343
}
4444
}

generated-docs/Network/HTTP.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Module Network.HTTP
2+
3+
#### `request`
4+
5+
``` purescript
6+
request :: forall e. Request -> Aff e Response
7+
```
8+
9+
#### `get'`
10+
11+
``` purescript
12+
get' :: forall e. Request -> Aff e Response
13+
```
14+
15+
#### `get`
16+
17+
``` purescript
18+
get :: forall e. String -> Aff e Response
19+
```
20+
21+
#### `post'`
22+
23+
``` purescript
24+
post' :: forall e. Request -> Aff e Response
25+
```
26+
27+
#### `post`
28+
29+
``` purescript
30+
post :: forall e. String -> Aff e Response
31+
```
32+
33+
#### `postWithBody`
34+
35+
``` purescript
36+
postWithBody :: forall e. String -> String -> Aff e Response
37+
```
38+
39+
#### `put'`
40+
41+
``` purescript
42+
put' :: forall e. Request -> Aff e Response
43+
```
44+
45+
#### `put`
46+
47+
``` purescript
48+
put :: forall e. String -> Aff e Response
49+
```
50+
51+
#### `putWithBody`
52+
53+
``` purescript
54+
putWithBody :: forall e. String -> String -> Aff e Response
55+
```
56+
57+
#### `patch'`
58+
59+
``` purescript
60+
patch' :: forall e. Request -> Aff e Response
61+
```
62+
63+
#### `patch`
64+
65+
``` purescript
66+
patch :: forall e. String -> Aff e Response
67+
```
68+
69+
#### `patchWithBody`
70+
71+
``` purescript
72+
patchWithBody :: forall e. String -> String -> Aff e Response
73+
```
74+
75+
#### `delete'`
76+
77+
``` purescript
78+
delete' :: forall e. Request -> Aff e Response
79+
```
80+
81+
#### `delete`
82+
83+
``` purescript
84+
delete :: forall e. String -> Aff e Response
85+
```
86+
87+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Module Network.HTTP.Internal
2+
3+
#### `toInternalRequest`
4+
5+
``` purescript
6+
toInternalRequest :: Request -> Request
7+
```
8+
9+
#### `fromInternalResponse`
10+
11+
``` purescript
12+
fromInternalResponse :: Response -> Response
13+
```
14+
15+
#### `Platform`
16+
17+
``` purescript
18+
data Platform
19+
= Node
20+
| Browser
21+
| Other
22+
```
23+
24+
#### `determinePlatform`
25+
26+
``` purescript
27+
determinePlatform :: Platform
28+
```
29+
30+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Module Network.HTTP.Internal.Browser
2+
3+
#### `request`
4+
5+
``` purescript
6+
request :: forall e. Request -> Aff e Response
7+
```
8+
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Module Network.HTTP.Internal.Node
2+
3+
#### `request`
4+
5+
``` purescript
6+
request :: forall e. Request -> Aff e Response
7+
```
8+
9+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Module Network.HTTP.Internal.Types
2+
3+
#### `Request`
4+
5+
``` purescript
6+
newtype Request
7+
= Request { protocol :: String, hostname :: String, port :: Int, method :: String, path :: String, headers :: Foreign, user :: Foreign, password :: Foreign, body :: String, timeout :: Foreign }
8+
```
9+
10+
##### Instances
11+
``` purescript
12+
Show Request
13+
```
14+
15+
#### `Response`
16+
17+
``` purescript
18+
newtype Response
19+
= Response { statusCode :: Int, headers :: Foreign, body :: String }
20+
```
21+
22+
##### Instances
23+
``` purescript
24+
Show Response
25+
```
26+
27+
#### `defRequest`
28+
29+
``` purescript
30+
defRequest :: Request
31+
```
32+
33+

src/Network/HTTP/Internal.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,26 @@ function foreignHeadersToHeadersImpl(tuple) {
3737
);
3838
}
3939
return tuplePairs;
40-
}}}}
40+
};};};};
4141
}
4242

43+
function fromTupleImpl(fst) {
44+
return function(snd) {
45+
return function(pairs) {
46+
var o = {};
47+
// pairs is a PureScript Tuple list, not a JavaScript key:value
48+
// Object, so it needs to be iterated with this variant of for.
49+
for (var i = 0, len = pairs.length; i < len; i++) {
50+
var pair = pairs[i];
51+
var key = fst(pair)();
52+
var value = snd(pair)();
53+
o[key] = value;
54+
}
55+
return o;
56+
};};
57+
};
58+
59+
exports.undefined = undefined;
4360
exports.determinePlatformImpl = determinePlatformImpl;
4461
exports.foreignHeadersToHeadersImpl = foreignHeadersToHeadersImpl;
62+
exports.fromTupleImpl = fromTupleImpl;

src/Network/HTTP/Internal.purs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import Prelude (($), (<$>), (<>), (>>=), (<<<), map, show)
1010
import Control.Alt ((<|>))
1111
import Data.Array (catMaybes, head, last)
1212
import Data.Foldable (foldr)
13-
import Data.Foreign (Foreign, Prop, toForeign, writeObject)
14-
import Data.Foreign.Class ((.=))
15-
import Data.Foreign.Undefined (writeUndefined)
13+
import Data.Foreign (Foreign, toForeign)
1614
import Data.List (intercalate, null)
1715
import Data.List.NonEmpty (fromFoldable, singleton, toList) as L
18-
import Data.Map (fromFoldable, lookup, toList)
16+
import Data.Map (fromFoldable, lookup, toUnfoldable)
1917
import Data.Maybe (Maybe(Just, Nothing), fromMaybe)
2018
import Data.Monoid (mempty)
2119
import Data.String (Pattern(Pattern), split, joinWith)
22-
import Data.Tuple (Tuple(Tuple))
20+
import Data.Tuple (Tuple(Tuple), fst, snd)
2321
import Data.URI (URI(URI))
2422
import Data.URI.Authority (Authority(Authority))
2523
import Data.URI.HierarchicalPart (HierarchicalPart(HierarchicalPart))
@@ -75,10 +73,21 @@ toInternalHeaderValue :: H.HeaderValue -> String
7573
toInternalHeaderValue (H.HVStr s) = s
7674
toInternalHeaderValue (H.HVList ss) = intercalate "," ss
7775

78-
toInternalHeaders :: H.Headers -> Array Prop
79-
toInternalHeaders = foldr toInternalHeader [] <<< toList
76+
77+
foreign import fromTupleImpl :: forall a b. (Tuple a b -> a) ->
78+
(Tuple a b -> b) ->
79+
Array (Tuple a b) ->
80+
Foreign
81+
82+
fromTuple :: forall a b. Array (Tuple a b) -> Foreign
83+
fromTuple = fromTupleImpl fst snd
84+
85+
toInternalHeaders :: H.Headers -> Array (Tuple String String)
86+
toInternalHeaders = foldr toInternalHeader [] <<< toUnfoldable'
8087
where
81-
toInternalHeader (Tuple name value) o = o <> [ show name .= toInternalHeaderValue value ]
88+
toInternalHeader (Tuple name value) o = o <> [ Tuple (show name) (toInternalHeaderValue value) ]
89+
toUnfoldable' :: H.Headers -> Array (Tuple H.HeaderName H.HeaderValue)
90+
toUnfoldable' = toUnfoldable
8291

8392
extractUser :: String -> Maybe String
8493
extractUser = head <<< split (Pattern ":")
@@ -94,6 +103,8 @@ extractAuth :: URI -> Maybe String
94103
extractAuth (URI _ (HierarchicalPart (Just (Authority auth _)) _) _ _) = auth
95104
extractAuth _ = Nothing
96105

106+
foreign import undefined :: Foreign
107+
97108
toInternalRequest :: Request -> Internal.Request
98109
toInternalRequest (Request r) = Internal.Request
99110
{ protocol: protocol'
@@ -102,7 +113,7 @@ toInternalRequest (Request r) = Internal.Request
102113
, port : port'
103114
, method : show r.method
104115
, path : fromEmpty defReq.path $ extractPath r.uri
105-
, headers : writeObject $ toInternalHeaders r.headers <> cookies'
116+
, headers : fromTuple $ toInternalHeaders r.headers <> cookies'
106117
-- If provided, the user's authentication takes precedence over authentication provided in the URI.
107118
, user : maybeToForeign $
108119
(r.auth >>= getUser) <|> (auth' >>= extractUser) <|> Nothing
@@ -117,7 +128,7 @@ toInternalRequest (Request r) = Internal.Request
117128

118129
maybeToForeign :: forall a. Maybe a -> Foreign
119130
maybeToForeign (Just x) = toForeign x
120-
maybeToForeign _ = writeUndefined
131+
maybeToForeign _ = undefined
121132

122133
-- XXX If the port is 80, and the protocol is 'https:' assume
123134
-- the the user left the default port unchanged, and change it
@@ -131,7 +142,7 @@ toInternalRequest (Request r) = Internal.Request
131142
defReq = extractRequestRecord Internal.defRequest
132143
protocol' = fromMaybe defReq.protocol $ extractProtocol r.uri
133144
port' = messWithPort protocol' $ fromMaybe defReq.port $ extractPort r.uri
134-
cookies' = if null r.cookies then [] else [ show H.Cookie .= stringify' r.cookies ]
145+
cookies' = if null r.cookies then [] else [ Tuple (show H.Cookie) (stringify' r.cookies) ]
135146
getUser (BasicAuth u _) = u
136147
getPassword (BasicAuth _ p) = p
137148
auth' = extractAuth r.uri

src/Network/HTTP/Internal/Types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
exports.undefined = undefined;

0 commit comments

Comments
 (0)