Repository API » History » Version 13
koszko, 11/19/2021 11:22 AM
minor corrections
1 | 1 | jahoti | # Repository API |
---|---|---|---|
2 | |||
3 | {{toc}} |
||
4 | |||
5 | ## Under current schema |
||
6 | |||
7 | ### Fetching script info |
||
8 | |||
9 | `hydrilla.example.com/script?n=helloscript` returns: |
||
10 | 4 | koszko | ``` javascript |
11 | 1 | jahoti | { |
12 | "name": "helloscript", |
||
13 | "location": "somedirectory/hello.js", |
||
14 | "sha256": "e4dbe4dba40e8bd159fb987b0f0cf2c243d7e6b9b9dc792e58dedf1fae38b0a1" |
||
15 | } |
||
16 | ``` |
||
17 | 2 | jahoti | or 404 Not Found in case "helloscript" script does not exist. `hydrilla.example.com/content/somedirectory/hello.js` holds the actual script source. |
18 | 1 | jahoti | |
19 | ### Fetching bag info |
||
20 | |||
21 | `hydrilla.example.com/bag?n=hellobag` returns: |
||
22 | 4 | koszko | ``` javascript |
23 | 1 | jahoti | { |
24 | "name": "hellobag", |
||
25 | "components": [["s", "helloscript"], ["s", "someotherscript"], ["b", "somebag"]] |
||
26 | } |
||
27 | ``` |
||
28 | or 404 Not Found in case "hellobag" bag does not exist. |
||
29 | |||
30 | ### Fetching pattern info |
||
31 | |||
32 | `hydrilla.example.com/pattern?n=https://example.org/a/*` returns: |
||
33 | 4 | koszko | ``` javascript |
34 | 1 | jahoti | { |
35 | "pattern": "https://example.org/a/*", |
||
36 | "payload": ["b", "hellobag"] |
||
37 | } |
||
38 | ``` |
||
39 | or 404 Not Found in case requested pattern does not exist. |
||
40 | |||
41 | ### Querying patterns that match given URL |
||
42 | |||
43 | Finally, `hydrilla.example.com/query?n=https://example.org/a/b` returns: |
||
44 | 4 | koszko | ``` javascript |
45 | 1 | jahoti | [{ |
46 | "pattern": "https://example.org/a/*", |
||
47 | "payload": ["b", "hellobag"] |
||
48 | }, { |
||
49 | "pattern": "https://example.org/a/b", |
||
50 | "payload": ["b", "fix_by_mrcooldev"] |
||
51 | }, { |
||
52 | "pattern": "https://example.org/a/b", |
||
53 | "payload": ["b", "mod_by_missgreatskill"] |
||
54 | }] |
||
55 | ``` |
||
56 | or in case no patterns match the requested URL, it returns just: |
||
57 | 4 | koszko | ``` javascript |
58 | 1 | jahoti | [] |
59 | ``` |
||
60 | or in case the URL is of wrong format it returns some HTTP error. |
||
61 | |||
62 | ## Under the upcoming schema |
||
63 | |||
64 | Also, once we get to do the redesign discussed in the <https://hydrillabugs.koszko.org/boards/1/topics/56>, the JSON will look more like the following. |
||
65 | |||
66 | 5 | koszko | *(note: this API schema somewhat resembles the [[Hydrilla on-disk data format]])* |
67 | |||
68 | 4 | koszko | ### Fetching resource info |
69 | "resource" is now the equivalent of what we used to call "bag". |
||
70 | |||
71 | 9 | koszko | `hydrilla.example.com/resources/helloapple` returns: |
72 | 4 | koszko | ``` javascript |
73 | 1 | jahoti | { |
74 | 9 | koszko | "source_name": "hello", |
75 | "source_copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
76 | "source_licenses": "CC0-1.0", |
||
77 | 1 | jahoti | "type": "resource", |
78 | 5 | koszko | "identifier": "helloapple", |
79 | "long_name": "Hello Apple", |
||
80 | 4 | koszko | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
81 | 7 | koszko | "version": [2021, 11, 10], |
82 | "revision": 1, |
||
83 | 4 | koszko | "description": "greets an apple", |
84 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
85 | "licenses": "CC0-1.0", |
||
86 | "dependencies": ["hello-message"], |
||
87 | "scripts": [ |
||
88 | 12 | koszko | { |
89 | "file": "hello.js", |
||
90 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
91 | "licenses": ["CC0-1.0", "or", "GPL-3.0-or-later"], |
||
92 | "sha256": "04d9c4e50c1ce40f9b7b7699a9202f23eaee31069e288502284dbbea7a38e468" |
||
93 | }, { |
||
94 | "file": "bye.js", |
||
95 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
96 | "licenses": "CC0-1.0", |
||
97 | "sha256": "92ae552d06ef22b48cef926861b6adec522ea08906e3dc5ae2705c1175b8fc48" |
||
98 | } |
||
99 | 1 | jahoti | ] |
100 | } |
||
101 | ``` |
||
102 | |||
103 | 9 | koszko | or 404 Not Found in case resource "helloapple" does not exists. If multiple versions are available, newest version's JSON description gets returned. A different one can be retrieved by specifying a "ver" parameter to GET request (e.g. by appending `?ver=2021.11.2-2` to the URL). Alternatively, a JSON list of all versions of a resource definition can be obtained by specifying "?ver=all". "hello.js" can then be retrieved by issuing GET request to `hydrilla.example.com/sources/hello/hello.js`. |
104 | 4 | koszko | |
105 | 1 | jahoti | ### Fetching mapping info |
106 | "mapping" is now a set of what we used to call "pattern". |
||
107 | 4 | koszko | |
108 | 9 | koszko | `hydrilla.example.com/mappings/example-org-minimal` returns: |
109 | 1 | jahoti | ``` javascript |
110 | { |
||
111 | 9 | koszko | "source_name": "example-org-fixes-new", |
112 | "source_copyright": [{"years": ["2021-2022"], "holder": "John Smith"}], |
||
113 | "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"], |
||
114 | 1 | jahoti | "type": "mapping", |
115 | "identifier": "example-org-minimal", |
||
116 | 4 | koszko | "long_name": "Example.org Minimal", |
117 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
118 | 9 | koszko | "version": [2022, 5, 10], |
119 | 1 | jahoti | "description": "suckless something something", |
120 | 8 | koszko | "payloads": [ |
121 | 12 | koszko | { |
122 | 4 | koszko | "pattern": "https://example.org/a/*", |
123 | 1 | jahoti | "payload": "some-KISS-resource" |
124 | 4 | koszko | }, { |
125 | "pattern": "https://example.org/t/*", |
||
126 | 1 | jahoti | "payload": "another-KISS-resource" |
127 | 4 | koszko | } |
128 | 1 | jahoti | ] |
129 | } |
||
130 | ``` |
||
131 | 9 | koszko | or 404 Not Found in case "example-org-minimal" resource does not exist. If multiple versions are available, newest version's JSON description gets returned. A different one can be retrieved by specifying a "ver" parameter to GET request (e.g. by appending `?ver=2021.11.2-2` to the URL). Alternatively, a JSON list of all versions of a mapping definition can be obtained by specifying "?ver=all". |
132 | 1 | jahoti | |
133 | 9 | koszko | ### Fetching license info |
134 | `hydrilla.example.com/licenses/GPL-3.0-only` returns: |
||
135 | ``` javascript |
||
136 | { |
||
137 | "source_name": "common-licenses", |
||
138 | "source_copyright": [{"years": ["2021"], "holder": "Hydrilla developers"}], |
||
139 | "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"], |
||
140 | "type": "license", |
||
141 | "identifier": "GPL-3.0-only", |
||
142 | "long_name": "GNU General Public License v3.0 only", |
||
143 | "revision": 2, |
||
144 | "legal_text": [{ |
||
145 | "format": "text/plain", |
||
146 | 13 | koszko | "file": "gpl-3.0.txt", |
147 | "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" |
||
148 | 1 | jahoti | }, { |
149 | "format": "text/html", |
||
150 | 13 | koszko | "file": "gpl-3.0.html", |
151 | "sha256": "f20948605b5d8e349977579aae01357e50f9fe4d158fc044d33c35b5fab41684" |
||
152 | 1 | jahoti | }], |
153 | 9 | koszko | "notice": { |
154 | 13 | koszko | "file": "gpl-3.0-notice.txt", |
155 | "sha256": "46085ca5f53d3f7818c452c9efc6850af4c38075ad4da44eb51fd97d9e84d970" |
||
156 | 11 | koszko | } |
157 | 9 | koszko | } |
158 | ``` |
||
159 | or 404 Not Found in case "GPL-3.0-only" license does not exist. License text can then be retrieved by issuing GET request to `hydrilla.example.com/sources/common-licenses/gpl-3.0.txt`. Notice used with the license (if applicable, as in the case of the GPL) can be retrieved from `hydrilla.example.com/sources/common-licenses/gpl-3.0-notice.txt`. |
||
160 | |||
161 | 1 | jahoti | ### Querying patterns that match given url |
162 | |||
163 | 9 | koszko | `hydrilla.example.com/query?url=https://example.org/a/b` returns: |
164 | 1 | jahoti | ``` javascript |
165 | [{ |
||
166 | 9 | koszko | "source_name": "example-org-fixes-new", |
167 | "source_copyright": [{"years": ["2021-2022"], "holder": "John Smith"}], |
||
168 | "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"], |
||
169 | 1 | jahoti | "type": "mapping", |
170 | 4 | koszko | "identifier": "example_org_minimal", |
171 | "long_name": "Example.org Minimal", |
||
172 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
173 | 7 | koszko | "version": [2021, 11, 10], |
174 | 1 | jahoti | "description": "suckless something something", |
175 | 8 | koszko | "payloads": [{ |
176 | 1 | jahoti | "pattern": "https://example.org/a/*", |
177 | "payload": "some-KISS-resource" |
||
178 | }, { |
||
179 | "pattern": "https://example.org/t/*", |
||
180 | "payload": "another-KISS-resource" |
||
181 | }] |
||
182 | }, { |
||
183 | 9 | koszko | "source_name": "example-org-fixes-new", |
184 | "source_copyright": [{ |
||
185 | "years": ["2021"], |
||
186 | "holder": "JavaScript Hooky-Gooky Inc." |
||
187 | }, { |
||
188 | "years": ["2021"], |
||
189 | "holder": "Abdul Ihn Ah-Ersh" |
||
190 | }], |
||
191 | "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"], |
||
192 | 4 | koszko | "type": "mapping", |
193 | "identifier": "example_org_experimantal", |
||
194 | "long_name": "Example.org Experimantal" |
||
195 | "uuid": "edc86a6a-2911-422f-901f-08edc00391b4", |
||
196 | 7 | koszko | "version": [0, 4], |
197 | 4 | koszko | "description": "[...]; patches are WANTED!", |
198 | 8 | koszko | "payloads": [{ |
199 | 1 | jahoti | "pattern": "https://example.org/**", |
200 | "payload": "quick-and-dirty-resource" |
||
201 | }] |
||
202 | }] |
||
203 | ``` |
||
204 | |||
205 | or `[]` in case no mappings match that URL. In case many versions of some mapping match the URL, only the most current of those versions that do is included. In case the URL is of wrong format, 400 Bad Request is returned. |
||
206 | |||
207 | ### Fetching source info |
||
208 | By "source" we mean contents of an index.json file from which item definitions come. |
||
209 | |||
210 | 12 | koszko | `hydrilla.example.com/sources/hello/index.json` could return something like: |
211 | 1 | jahoti | ``` javascript |
212 | 12 | koszko | // SPDX-License-Identifier: CC0-1.0 |
213 | |||
214 | // Copyright (C) 2021 Wojtek Kosior |
||
215 | // Available under the terms of Creative Commons Zero v1.0 Universal. |
||
216 | |||
217 | 9 | koszko | { |
218 | "schema_version": [0, 2], |
||
219 | "schema_revision": 1, |
||
220 | "copyright": [ |
||
221 | 12 | koszko | { |
222 | "years": ["2021"], |
||
223 | "holder": "Wojtek Kosior" |
||
224 | } |
||
225 | 9 | koszko | ], |
226 | "licenses": "CC0-1.0", |
||
227 | 12 | koszko | "upstream_url": "https://git.koszko.org/pydrilla/tree/src/test/example_content/hello", |
228 | "package_url": "https://git.koszko.org/pydrilla/tree/src/test/example_content/hello", |
||
229 | 9 | koszko | "definitions": [ |
230 | 12 | koszko | { |
231 | "type": "resource", |
||
232 | "identifier": "helloapple", |
||
233 | "long_name": "Hello Apple", |
||
234 | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
||
235 | "version": [2021, 11, 10], |
||
236 | 9 | koszko | "revision": 1, |
237 | 12 | koszko | "description": "greets an apple", |
238 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
239 | "licenses": "CC0-1.0", |
||
240 | "dependencies": ["hello-message"], |
||
241 | "scripts": [ |
||
242 | { |
||
243 | "file": "hello.js", |
||
244 | "copyright": "auto", |
||
245 | "licenses": "auto" |
||
246 | }, { |
||
247 | "file": "bye.js" |
||
248 | } |
||
249 | ] |
||
250 | }, { |
||
251 | "type": "resource", |
||
252 | "identifier": "hello-message", |
||
253 | "long_name": "Hello Message", |
||
254 | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
||
255 | "version": [2021, 11, 10], |
||
256 | "revision": 2, |
||
257 | "description": "define messages for saying hello and bye", |
||
258 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
259 | "licenses": "CC0-1.0", |
||
260 | "scripts": [{"file": "message.js"}] |
||
261 | }, { |
||
262 | "type": "mapping", |
||
263 | "identifier": "helloapple", |
||
264 | "long_name": "Hello Apple", |
||
265 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
266 | "version": [2021, 11, 10], |
||
267 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
268 | "payloads": [ |
||
269 | { |
||
270 | "pattern": "https://hydrillabugs.koszko.org/***", |
||
271 | "payload": "helloapple" |
||
272 | }, |
||
273 | { |
||
274 | "pattern": "https://hachettebugs.koszko.org/***", |
||
275 | "payload": "helloapple" |
||
276 | } |
||
277 | ] |
||
278 | }, { |
||
279 | "type": "license", |
||
280 | "identifier": "CC0-1.0", |
||
281 | "long_name": "Creative Commons Zero v1.0 Universal", |
||
282 | "revision": 2, |
||
283 | "legal_text": [ |
||
284 | { |
||
285 | "format": "text/plain", |
||
286 | "file": "cc0.txt" |
||
287 | } |
||
288 | ] |
||
289 | } |
||
290 | 9 | koszko | ] |
291 | 1 | jahoti | } |
292 | ``` |
||
293 | |||
294 | 12 | koszko | Returned are the contents of index.json that Hydrilla processes to construct other definitions. "//" comments are allowed to appear there as an extension to JSON. For details about this file's structure, see [[Hydrilla on-disk data format#Format-of-an-indexjson|here]]. |