Skip to content

Commit 2117fcc

Browse files
committed
Move URL parameter to front of functions
1 parent 5bb4041 commit 2117fcc

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ type AffjaxResponse a = { response :: a, headers :: [ResponseHeader], status ::
3434

3535
The type of records that will be received as an Affjax response.
3636

37+
#### `URL`
38+
39+
``` purescript
40+
type URL = String
41+
```
42+
43+
Type alias for URL strings to aid readability of types.
44+
3745
#### `url`
3846

3947
``` purescript
40-
url :: Option AffjaxOptions String
48+
url :: Option AffjaxOptions URL
4149
```
4250

4351
Sets the URL for a request.
@@ -101,49 +109,49 @@ Runs a request directly in Eff.
101109
#### `get`
102110

103111
``` purescript
104-
get :: forall e a. Responsable a -> String -> Affjax e a
112+
get :: forall e a. URL -> Responsable a -> Affjax e a
105113
```
106114

107115

108116
#### `post`
109117

110118
``` purescript
111-
post :: forall e a. Responsable a -> String -> RequestContent -> Affjax e a
119+
post :: forall e a. URL -> Responsable a -> RequestContent -> Affjax e a
112120
```
113121

114122

115123
#### `post_`
116124

117125
``` purescript
118-
post_ :: forall e. String -> RequestContent -> Affjax e Unit
126+
post_ :: forall e. URL -> RequestContent -> Affjax e Unit
119127
```
120128

121129

122130
#### `put`
123131

124132
``` purescript
125-
put :: forall e a. Responsable a -> String -> RequestContent -> Affjax e a
133+
put :: forall e a. URL -> Responsable a -> RequestContent -> Affjax e a
126134
```
127135

128136

129137
#### `put_`
130138

131139
``` purescript
132-
put_ :: forall e. String -> RequestContent -> Affjax e Unit
140+
put_ :: forall e. URL -> RequestContent -> Affjax e Unit
133141
```
134142

135143

136144
#### `delete`
137145

138146
``` purescript
139-
delete :: forall e a. Responsable a -> String -> Affjax e a
147+
delete :: forall e a. URL -> Responsable a -> Affjax e a
140148
```
141149

142150

143151
#### `delete_`
144152

145153
``` purescript
146-
delete_ :: forall e. String -> Affjax e Unit
154+
delete_ :: forall e. URL -> Affjax e Unit
147155
```
148156

149157

src/Network/HTTP/Affjax.purs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Network.HTTP.Affjax
33
, Affjax()
44
, AffjaxOptions()
55
, AffjaxResponse()
6+
, URL()
67
, url, method, content, headers, username, password
78
, affjax
89
, affjax'
@@ -43,8 +44,11 @@ type AffjaxResponse a =
4344
, response :: a
4445
}
4546

47+
-- | Type alias for URL strings to aid readability of types.
48+
type URL = String
49+
4650
-- | Sets the URL for a request.
47-
url :: Option AffjaxOptions String
51+
url :: Option AffjaxOptions URL
4852
url = opt "url"
4953

5054
-- | Sets the HTTP method for a request.
@@ -92,32 +96,32 @@ affjax' (Responsable read ty) opts eb cb =
9296
Left err -> eb $ error (show err)
9397
Right res' -> cb res'
9498

95-
get :: forall e a. Responsable a -> String -> Affjax e a
96-
get r addr = affjax r $ method := GET
97-
<> url := addr
99+
get :: forall e a. URL -> Responsable a -> Affjax e a
100+
get u r = affjax r $ method := GET
101+
<> url := u
98102

99-
post :: forall e a. Responsable a -> String -> RequestContent -> Affjax e a
100-
post r u c = affjax r $ method := POST
103+
post :: forall e a. URL -> Responsable a -> RequestContent -> Affjax e a
104+
post u r c = affjax r $ method := POST
101105
<> url := u
102106
<> content := c
103107

104-
post_ :: forall e. String -> RequestContent -> Affjax e Unit
105-
post_ = post rUnit
108+
post_ :: forall e. URL -> RequestContent -> Affjax e Unit
109+
post_ = flip post rUnit
106110

107-
put :: forall e a. Responsable a -> String -> RequestContent -> Affjax e a
108-
put r u c = affjax r $ method := PUT
111+
put :: forall e a. URL -> Responsable a -> RequestContent -> Affjax e a
112+
put u r c = affjax r $ method := PUT
109113
<> url := u
110114
<> content := c
111115

112-
put_ :: forall e. String -> RequestContent -> Affjax e Unit
113-
put_ = put rUnit
116+
put_ :: forall e. URL -> RequestContent -> Affjax e Unit
117+
put_ = flip put rUnit
114118

115-
delete :: forall e a. Responsable a -> String -> Affjax e a
116-
delete r u = affjax r $ method := DELETE
119+
delete :: forall e a. URL -> Responsable a -> Affjax e a
120+
delete u r = affjax r $ method := DELETE
117121
<> url := u
118122

119-
delete_ :: forall e. String -> Affjax e Unit
120-
delete_ = delete rUnit
123+
delete_ :: forall e. URL -> Affjax e Unit
124+
delete_ = flip delete rUnit
121125

122126
foreign import unsafeAjax
123127
"""

test/Main.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main = do
4242
liftEff $ either traceAny traceAny res
4343

4444
launchAff $ do
45-
res <- attempt $ get rInt8Array "/arrayview"
45+
res <- attempt $ get "/arrayview" rInt8Array
4646
liftEff $ either traceAny traceAny res
4747

4848
go :: forall e. Options AffjaxOptions -> Eff (ajax :: Ajax, trace :: Trace | e) Unit

0 commit comments

Comments
 (0)