-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.aro
More file actions
47 lines (41 loc) · 1.7 KB
/
api.aro
File metadata and controls
47 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(* HTTP Route Handlers *)
(serveStatic: StatusPost API) {
Extract the <file> from the <pathParameters: file>.
Create the <template-path> with "static/" ++ <file>.
Transform the <content> from the <template: template-path>.
Return an <OK: status> with <content>.
}
(homePage: StatusPost API) {
Retrieve the <all-messages> from the <message-repository>.
Extract the <recent-messages: 0-19> from the <all-messages>.
Transform the <html> from the <template: index.html>.
Return an <OK: status> with <html>.
}
(getMessages: StatusPost API) {
Retrieve the <all-messages> from the <message-repository>.
Extract the <recent-messages: 0-19> from the <all-messages>.
Return an <OK: status> with <recent-messages>.
}
(postMessage: StatusPost API) {
Extract the <body> from the <request: body>.
Extract the <message-text: message> from the <body>.
Create the <message: Message> with {
message: <message-text>,
createdAt: <now>
}.
Store the <message> into the <message-repository>.
Broadcast the <message> to the <websocket>.
Return a <Created: status> with <message>.
}
(getMetrics: StatusPost API) {
Return an <OK: status> with <metrics: prometheus>.
}
(* Repository Observer - cleanup when message count exceeds 40 *)
(Cleanup Messages: message-repository Observer) when <message-repository: count> > 40 {
Retrieve the <all-messages> from the <message-repository>.
Extract the <keep-messages: 0-19> from the <all-messages>.
Clear the <all> from the <message-repository>.
Store the <keep-messages> into the <message-repository>.
Log "Cleaned up messages, kept last 20" to the <console>.
Return an <OK: status> for the <cleanup>.
}