on master help sign in
17 files changed+247−13
since splitsnapshots
unifiedsplit
LICENSE Procfile+1 Setup.hs app.json app/Main.hs+7−1 docs.md docs/Docs.hs+2−2 package.yaml+5−4 readme.md+223 src/Data/CyclicBuffer.hs src/Data/Error.hs src/Foo/Data.hs+2−2 src/Lib.hs+4−1 src/Network/Bacon.hs+3−3 stack.yaml swagger/Swagger.hs test/Spec.hs
LICENSEmode 100644 → 100755

Only the mode changed.

Procfilenew file+1
@@ -0,0 +1 @@
1+web: websuck1t-exe
Setup.hsmode 100644 → 100755

Only the mode changed.

app.jsonmode 100644 → 100755

Only the mode changed.

app/Main.hsmode 100644 → 100755+7−1
@@ -2,9 +2,15 @@ module Main where
22
33import Network.Wai.Handler.Warp (run)
44import Servant.Server (serve)
5+import System.Environment
56import Lib
7+import Network.Wai.Middleware.Cors
68
79main :: IO ()
810main = do
11+ env <- lookupEnv "PORT"
12+ let port = maybe 2000 read env :: Int
13+ putStrLn $ "Starting on port: " ++ show port
14+ print env
915 srv <- createServer
10− run 2000 $ serve server srv
16+ run port $ simpleCors $ serve server srv
docs.mdmode 100644 → 100755

Only the mode changed.

docs/Docs.hsmode 100644 → 100755+2−2
@@ -26,7 +26,7 @@ instance ToCapture (Capture "first" T.Text) where
2626 toCapture _ = DocCapture "first" "The first name of the user."
2727
2828instance ToSample Foo.Data.Post where
29− toSamples _ = samples $ Post <$> [1, 4, 7, 194] <*> [4, 7, 92] <*> ["This is the post body", "This is another post body"]
29+ toSamples _ = samples $ Post `fmap` [1, 4, 7, 194] <*> [4, 7, 92] <*> ["This is the post body", "This is another post body"]
3030
3131instance ToSample User where
3232 toSamples _ = samples [
@@ -39,7 +39,7 @@ instance ToCapture (Capture "second" T.Text) where
3939 toCapture _ = DocCapture "second" "The second name of the user."
4040
4141instance ToSample (TokenizedResponse [Foo.Data.Post]) where
42− toSamples _ = samples $ TokenizedResponse <$> [1, 46, 193, 7] <*> [map snd $ toSamples (Proxy :: Proxy Foo.Data.Post)]
42+ toSamples _ = samples $ TokenizedResponse `fmap` [1, 46, 193, 7] <*> [map snd $ toSamples (Proxy :: Proxy Foo.Data.Post)]
4343
4444instance ToCapture (Capture "id" Int) where
4545 toCapture _ = DocCapture "id" "The id of the entity you want to query."
package.yamlmode 100644 → 100755+5−4
@@ -36,6 +36,7 @@ dependencies:
3636- servant-websockets
3737- websockets
3838- lens
39+- wai-cors
3940
4041library:
4142 source-dirs: src
@@ -49,7 +50,7 @@ executables:
4950 - -rtsopts
5051 - -with-rtsopts=-N
5152 dependencies:
52− - foo
53+ - websuck1t
5354 docs-exe:
5455 main: Docs.hs
5556 source-dirs: docs
@@ -58,7 +59,7 @@ executables:
5859 - -rtsopts
5960 - -with-rtsopts=-N
6061 dependencies:
61− - foo
62+ - websuck1t
6263 swagger-exe:
6364 main: Swagger.hs
6465 source-dirs: swagger
@@ -67,7 +68,7 @@ executables:
6768 - -rtsopts
6869 - -with-rtsopts=-N
6970 dependencies:
70− - foo
71+ - websuck1t
7172
7273tests:
7374 foo-test:
@@ -78,4 +79,4 @@ tests:
7879 - -rtsopts
7980 - -with-rtsopts=-N
8081 dependencies:
81− - foo
82+ - websuck1t
readme.mdnew file+223
@@ -0,0 +1,223 @@
1+# A server example with WebSockets
2+
3+_url: [`https://websuck1t.herokuapp.com`](https://websuck1t.herokuapp.com)_
4+
5+# Methods
6+
7+## GET /posts/all
8+
9+### Response:
10+
11+- Status code 200
12+- Headers: []
13+
14+- Supported content types are:
15+
16+ - `application/json`
17+
18+- Example (`application/json`):
19+
20+```javascript
21+{
22+ "token": 1,
23+ "response": [
24+ {
25+ "postBody": "This is the post body",
26+ "postAuthor": 4,
27+ "postId": 1
28+ },
29+ {
30+ "postBody": "This is another post body",
31+ "postAuthor": 4,
32+ "postId": 2
33+ },
34+ {
35+ "postBody": "This is the post body",
36+ "postAuthor": 7,
37+ "postId": 3
38+ },
39+ {
40+ "postBody": "This is another post body",
41+ "postAuthor": 7,
42+ "postId": 4
43+ },
44+ {
45+ "postBody": "This is the post body",
46+ "postAuthor": 92,
47+ "postId": 5
48+ },
49+ {
50+ "postBody": "This is another post body",
51+ "postAuthor": 92,
52+ "postId": 6
53+ }
54+ ]
55+}
56+```
57+
58+## GET /users/:id
59+
60+Retrieves a user with the given `id`.
61+
62+#### If there is no user with the given `id`, the method returns error `404`.
63+
64+### Captures:
65+
66+- *id*: The id of the entity you want to query.
67+
68+### Response:
69+
70+- Status code 200
71+- Headers: []
72+
73+- Supported content types are:
74+
75+ - `application/json`
76+
77+- Example (`application/json`):
78+
79+```javascript
80+{
81+ "userName": {
82+ "secondName": "Leonidovich",
83+ "firstName": "Seva"
84+ },
85+ "userId": 1
86+}
87+```
88+
89+- Example (`application/json`):
90+
91+```javascript
92+{
93+ "userName": {
94+ "secondName": "Barovich",
95+ "firstName": "Foo"
96+ },
97+ "userId": 42
98+}
99+```
100+
101+- Example (`application/json`):
102+
103+```javascript
104+{
105+ "userName": {
106+ "secondName": "Fooovich",
107+ "firstName": "Bar"
108+ },
109+ "userId": 69
110+}
111+```
112+
113+- Example (`application/json`):
114+
115+```javascript
116+{
117+ "userName": {
118+ "secondName": "Quixovich",
119+ "firstName": "Qux"
120+ },
121+ "userId": 8
122+}
123+```
124+
125+## WebSocket /posts/subscribe/:token
126+
127+You access the web socket with the web socket protocol. I. e. `https://` -> `ws://`.
128+
129+Open a web socket from the given `token` for receiving events about new and deleted posts.
130+
131+#### Returns error `498` if the supplied token has expired or is invalid.
132+
133+
134+### Captures:
135+
136+- *token*: The token, received with the previous request.
137+
138+### Response:
139+
140+```javascript
141+{
142+ "token": 1828,
143+ "response": {
144+ "deleted": [
145+ 1819,
146+ 1835,
147+ 1843
148+ ],
149+ "added": [
150+ 1844,
151+ 1845,
152+ 1846
153+ ]
154+ }
155+}
156+```
157+
158+## GET /posts/:id
159+
160+#### If there is no post with the given `id`, the method returns error `404`.
161+
162+### Captures:
163+
164+- *id*: The id of the entity you want to query.
165+
166+### Response:
167+
168+- Status code 200
169+- Headers: []
170+
171+- Supported content types are:
172+
173+ - `application/json`
174+
175+- Example (`application/json`):
176+
177+```javascript
178+{
179+ "postBody": "This is the post body",
180+ "postAuthor": 4,
181+ "postId": 1
182+}
183+```
184+
185+- Example (`application/json`):
186+
187+```javascript
188+{
189+ "postBody": "This is another post body",
190+ "postAuthor": 4,
191+ "postId": 1
192+}
193+```
194+
195+- Example (`application/json`):
196+
197+```javascript
198+{
199+ "postBody": "This is the post body",
200+ "postAuthor": 7,
201+ "postId": 1
202+}
203+```
204+
205+- Example (`application/json`):
206+
207+```javascript
208+{
209+ "postBody": "This is another post body",
210+ "postAuthor": 7,
211+ "postId": 1
212+}
213+```
214+
215+- Example (`application/json`):
216+
217+```javascript
218+{
219+ "postBody": "This is the post body",
220+ "postAuthor": 92,
221+ "postId": 1
222+}
223+```
src/Data/CyclicBuffer.hsmode 100644 → 100755

Only the mode changed.

src/Data/Error.hsmode 100644 → 100755

Only the mode changed.

src/Foo/Data.hsmode 100644 → 100755+2−2
@@ -92,7 +92,7 @@ type Token = Int
9292
9393data TokenizedResponse d = TokenizedResponse {
9494 token :: Token,
95− reponse :: d
95+ response :: d
9696} deriving Generic
9797
9898instance ToJSON d => ToJSON (TokenizedResponse d)
@@ -165,7 +165,7 @@ startAddingPosts lim cfg = do
165165 let us = users cfg
166166 let ps = posts cfg
167167
168− a <- liftIO $ loremBacon (manager cfg) (Just AllMeat) (Just lim) (Just False)
168+ a <- liftIO $ loremBacon (manager cfg) (Just AllMeat) (Just lim) (Just 0)
169169 g <- liftIO newStdGen
170170 let rns = randoms g
171171
src/Lib.hsmode 100644 → 100755+4−1
@@ -38,7 +38,10 @@ type API = "users" :> Capture "id" UserId :> Get '[JSON] User
3838createServer :: IO (Server API)
3939createServer = do
4040 cfg <- createConfig
41− atomically $ newUser cfg "Kostya" "Designer"
41+ atomically $ newUser cfg "Kostya" "Designerovich"
42+ atomically $ newUser cfg "Anna" "Androidovna"
43+ atomically $ newUser cfg "Darya" "Aiphonovna"
44+ atomically $ newUser cfg "Ilya" "Serverovich"
4245 return $ hoistServer server (createApp cfg) serverAPI
4346
4447server :: Proxy API
src/Network/Bacon.hsmode 100644 → 100755+3−3
@@ -21,15 +21,15 @@ instance ToHttpApiData LoremType where
2121 toQueryParam MeatAndFiller = "meat-and-filler"
2222 toQueryParam AllMeat = "all-meat"
2323
24−type API = QueryParam "type" LoremType :> QueryParam "paras" Int :> QueryParam "start-with-lorem" Bool :> Get '[JSON] [Text]
24+type API = QueryParam "type" LoremType :> QueryParam "paras" Int :> QueryParam "start-with-lorem" Int :> Get '[JSON] [Text]
2525
2626clientAPI :: Proxy API
2727clientAPI = Proxy
2828
29−loremBacon' :: Maybe LoremType -> Maybe Int -> Maybe Bool -> ClientM [Text]
29+loremBacon' :: Maybe LoremType -> Maybe Int -> Maybe Int -> ClientM [Text]
3030loremBacon' = client clientAPI
3131
32−loremBacon :: Manager -> Maybe LoremType -> Maybe Int -> Maybe Bool -> IO (Maybe [Text])
32+loremBacon :: Manager -> Maybe LoremType -> Maybe Int -> Maybe Int -> IO (Maybe [Text])
3333loremBacon mng a b c = do
3434 let env = mkClientEnv mng (BaseUrl Https "baconipsum.com" 443 "api")
3535 res <- runClientM (loremBacon' a b c) env
stack.yamlmode 100644 → 100755

Only the mode changed.

swagger/Swagger.hsmode 100644 → 100755

Only the mode changed.

test/Spec.hsmode 100644 → 100755

Only the mode changed.