-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.html
160 lines (133 loc) · 7.86 KB
/
help.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<head>
<title>rQUE documentation</title>
</head>
<body>
<h1>rQUE</h1>
<h2>Running the server</h2>
<h3>Usage and examples</h3>
<p>The only (optional) argument is the port
<br><strong><code>$ rque {PORT}</code></strong></p>
<p>Example1: Runs the server normally at the default port (8080) or at a custom port specified by an environment variable
<br><strong><code>$ rque</strong></code></p>
<p>Example2: Runs the server at port 23456
<br><strong><code>$ rque 23456</strong></code></p>
<h3>Environment variables</h3>
<p><strong>RQUE_CUSTOMPORT</strong>
<br>Type: Number
<br>Descr.: Custom port. The server will first look into the port argument before this environment variable</p>
<p><strong>RQUE_SECRETKEY</strong>
<br>Type: String
<br>Descr.: Secret key that acts as a token for authorising all requests. All request must include an 'Authorization' header of type 'Bearer' like this one: <code>{ 'Authorization' : 'Bearer TheSecretKey' }</code>. The only exception of this is the GET request to the '/help' route if the client is '127.0.0.1'</p>
<h2>How data is stored</h2>
<h3>Terminology</h3>
<p>→ The data is stored in a large hashmap, where each key is the name of a group and each value is the contents of the group
<br>→ Groups are lists of lists of strings ( List[List[String]] ), they contain items
<br>→ Each item inside a group is a list o strings ( [List[String] ) with the first index being the 'head' of the item
<p>
<strong>
<code>
<pre>
{
'group 1':
[
['thing1'] ,
['thing2','bonus']
],
'group2':
[
['thing1']
],
'another group':
[
['headname1','data'],
['headname2','data'],
['headname3','data','more data']
]
}
</pre>
</code>
</strong>
</p>
<h3>Rules</h3>
<p>→ Items cannot have a length of zero, they must at least have the head
<br>→ 2 or more items in the same group cannot have the same head, and this is checked automatically by the program before adding new items to a group
<br>→ Each group name is unique and if a group does not exist when adding items, the group is created automatically before adding the new items
<br>→ A group can only exist as empty if all of its items have been removed manually</p>
<h2>API reference</h2>
<h3>Endpoints</h3>
<p>GET requests read existing data only, POST requests add data, and DELETE requests delete data
<br>All data modifications with POST and DELETE requests are printed in the console output
<p>GET /help
<br>Desc.: This help</p>
<p>GET /
<br>Desc.: It always returns HTTP 200
<br>Res. (200): <code>{}</code></p>
<p>GET /all
<br>Desc.: Recovers a list of existing group names
<br>Res. (JSON, 200): <code>{ 'status':200 , 'result' : List[String] }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg' : String }</code></p>
<p>GET /r/{name} | name: String
<br>Desc.: Recovers all the items of the specified group and its size (group_size key). Returns HTTP 206 (Partial response) if the group is empty
<br>Res. (JSON, 200): <code>{ 'status':200 , 'group_size' : Integer , 'group' : List[List[String]] }</code>
<br>Res. (JSON, 206): <code>{ 'status':206 , 'group_size':0 , 'group':[] }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg': String }</code></p>
<p>GET /r/{name}/size | name: String
<br>Desc.: Recovers only the size of the specified group (group_size key). Returns HTTP 206 (Partial response) if the group is empty
<br>Res. (JSON, 200): <code>{ 'status':200 , 'group_size' : Integer }</code>
<br>Res. (JSON, 206): <code>{ 'status':206 , 'group_size':0 }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg': String }</code></p>
<p>GET /r/{name}/s/{index} | name: String | index: Integer
<br>Desc.: Recovers a selected item from a group by its index
<br>Res. (JSON, 200): <code>{ 'status':200 , 'item' : List[String] }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg' : String }</code></p>
<p>GET /r/{name}/s/{index}/{qtty} | name: String | index: Integer | qtty: Integer
<br>Desc.: Recovers a slice of a group by selecting in range
<br>Res. (JSON, 200): <code>{ 'status':200 , 'slice' : List[List[String]] }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg': String }</code></p>
<p>POST /add-one
<br>JSON <code>{ 'name' : String , 'item': List[String] }</code>
<br>Desc.: Adds a new item to the bottom of an existing group (yes, it's like a queue) and tells wether the group has been created from scratch or not (newgroup key)
<br>Res. (JSON, 200): <code>{ 'status' : 200 , 'newgroup' : Bool }</code>
<br>Res. (JSON, 4xx): <code>{ 'status' : 4xx , 'msg' : String }</code></p>
<p>POST /add-mul
<br>JSON <code>{ 'name' : String , 'list': List[List[String]] , 'details': Bool }</code>
<br>Desc.: Adds multiple new items to a group and tells wether the group has been created from scratch or not ('newgroup' key in the response). Returns 206 if partially successful and in this case it will say the amount of items added ('items_succ' key), the ammount of items that could not be added ('items_fail' key), and if the 'details' key is set to true, a list of booleans will be returned, you can use this list to get a detailed view of the items that were added and the items that were not added
<br>Res. (JSON, 200): <code>{ 'status' : 200 , 'newgroup' : Bool }</code>
<br>Res. { 'details':true } (JSON, 206): <code>{ 'status' : 206 , 'newgroup' : Bool , items_succ: Integer , items_fail : Integer , details: List[Bool] }</code>
<br>Res. { 'details':false } (JSON, 206): <code>{ 'status' : 206 , 'newgroup' : Bool , items_succ: Integer , items_fail : Integer }</code>
<br>Res. (JSON, 4xx): <code>{ 'status' : 4xx , 'msg' : String }</code></p>
<p>DELETE /all
<br>Desc.: Deletes all groups. Use with caution<br>Res. (JSON, 200): <code>{ 'status': 200 }</code>
<br>Res. (JSON, 4xx): <code>{ 'status': 4xx , 'msg' : String }</code></p>
<p>DELETE /d/{name} | name: String
<br>Desc.: Delete a specific group along with its items
<br>Res. (JSON, 200): <code>{ 'status': 200 }</code>
<br>Res. (JSON, 4xx): <code>{ 'status': 4xx , 'msg' : String }</code></p>
<p>DELETE /d/{name}/{index}
<br>JSON <code>{ 'recover' : Bool }</code>
<br>Desc.: Deletes an item from a specified group. You can recover the deleted item in the response (with the 'recover' key)
<br>Res. { 'recover' : true } (JSON, 200): <code>{ 'status' : 200 , 'item' : List[String] }</code>
<br>Res. { 'recover' : false } (JSON, 200): <code>{ 'status' : 200 }</code>
<br>Res. (JSON, 4xx): <code>{ 'status' : 4xx , 'msg' : String }</code></p>
<p>DELETE /d/{name}/{index}/{qtty}
<br>JSON <code>{ 'recover' : Bool }</code>
<br>Desc.: Deletes multiple items selected in range. You can recover a slice of the deleted items in the response (with the 'recover' key)
<br>Res. { 'recover' : true } (JSON, 200): <code>{ 'status':200 , 'slice_size' : Integer , 'slice' : List[List[String]] }</code>
<br>Res. { 'recover' : false } (JSON, 200): <code>{ 'status':200 }</code>
<br>Res. (JSON, 4xx): <code>{ 'status':4xx , 'msg' : String }</code></p>
<h3>Range selection</h3>
<p>Range selection works by declaring a starting index and a quantity
<br>If the quantity is zero, all items after the starting index are selected, including the item in the starting index</p>
<p>Examples:</p>
<p>DELETE /d/queue1/3/2
<br>Deletes from the group 'queue1' the items no. 3 and 4, because the starting index is 3 and the quantity is 2</p>
<p>DELETE /d/stack/4/0
<br>Deletes all items in the group 'stack' leaving only the items 0, 1, 2 and 3. In this case the starting index is 3 and all the other items after the item no. 3 are also selected because the quantity is set to 0</p>
<p>GET /r/users/0/0
<br>Gets all items from the group 'users', because the index is 0 and the quantity is also 0</p>
</body>
</html>