Project

General

Profile

Repository API » History » Version 9

koszko, 11/13/2021 02:24 PM
Made some changes to proposed API. Added information about fetching of files referred to in json definitions

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
	{
89
	    "name": "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
	    "name": "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 1 jahoti
	{
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
            "file":   "gpl-3.0.txt"
147
        }, {
148
            "format": "text/html",
149
            "file":   "gpl-3.0.html"
150
        }],
151
    "notice": "gpl-3.0-notice.txt"
152
}
153
```
154
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`.
155
156 1 jahoti
### Querying patterns that match given url
157
158 9 koszko
`hydrilla.example.com/query?url=https://example.org/a/b` returns:
159 1 jahoti
``` javascript
160
[{
161 9 koszko
    "source_name": "example-org-fixes-new",
162
    "source_copyright": [{"years": ["2021-2022"], "holder": "John Smith"}],
163
    "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"],
164 1 jahoti
    "type": "mapping",
165 4 koszko
    "identifier": "example_org_minimal",
166
    "long_name": "Example.org Minimal",
167
    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
168 7 koszko
    "version": [2021, 11, 10],
169 1 jahoti
    "description": "suckless something something",
170 8 koszko
    "payloads": [{
171 1 jahoti
            "pattern":  "https://example.org/a/*",
172
            "payload":  "some-KISS-resource"
173
        }, {
174
            "pattern":  "https://example.org/t/*",
175
            "payload":  "another-KISS-resource"
176
        }]
177
}, {
178 9 koszko
    "source_name": "example-org-fixes-new",
179
    "source_copyright": [{
180
            "years": ["2021"],
181
            "holder": "JavaScript Hooky-Gooky Inc."
182
        }, {
183
            "years": ["2021"],
184
            "holder": "Abdul Ihn Ah-Ersh"
185
        }],
186
    "source_licenses": ["Apache-2.0", "and", "CC-BY-SA-4.0"],
187 4 koszko
    "type": "mapping",
188
    "identifier": "example_org_experimantal",
189
    "long_name": "Example.org Experimantal"
190
    "uuid": "edc86a6a-2911-422f-901f-08edc00391b4",
191 7 koszko
    "version": [0, 4],
192 4 koszko
    "description": "[...]; patches are WANTED!",
193 8 koszko
    "payloads": [{
194 1 jahoti
            "pattern":  "https://example.org/**",
195
            "payload":  "quick-and-dirty-resource"
196
        }]
197
}]
198
```
199
200
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.
201 9 koszko
202
### Fetching source info
203
By "source" we mean contents of an index.json file from which item definitions come.
204
205
`hydrilla.example.com/sources/hello` returns:
206
``` javascript
207
{
208
    "schema_version": [0, 2],
209
    "schema_revision": 1,
210
    "copyright":  [
211
	{
212
	    "years": ["2021"],
213
	    "holder": "Wojtek Kosior"
214
	}
215
    ],
216
    "licenses": "CC0-1.0",
217
    "upstream_url": "https://git.koszko.org/pydrilla/tree/example_content/hello",
218
    "package_url": "https://git.koszko.org/pydrilla/tree/example_content/hello",
219
    "definitions": [
220
	{
221
	    "type": "resource",
222
	    "identifier": "helloapple",
223
	    "long_name": "Hello Apple",
224
	    "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68",
225
	    "version": [2021, 11, 10],
226
	    "revision": 1,
227
	    "description": "greets an apple",
228
	    "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}],
229
	    "licenses": "CC0-1.0",
230
	    "dependencies": ["hello-message"],
231
	    "scripts": [
232
		{
233
		    "name": "hello.js",
234
		    "copyright": "auto",
235
		    "licenses":  "auto"
236
		}, {
237
		    "name":   "bye.js"
238
		}
239
	    ]
240
	}, {
241
	    "type":       "resource",
242
	    "identifier": "hello-message",
243
	    "long_name":  "Hello Message",
244
	    "uuid":       "1ec36229-298c-4b35-8105-c4f2e1b9811e",
245
	    "version":     [2021, 11, 10],
246
	    "revision":    2,
247
	    "description": "define messages for saying hello and bye",
248
	    "copyright":   [{"years": ["2021"], "holder": "Wojtek Kosior"}],
249
	    "licenses":    "CC0-1.0",
250
	    "scripts": [{"name": "message.js"}]
251
	}, {
252
	    "type": "mapping",
253
	    "identifier": "helloapple",
254
	    "long_name": "Hello Apple",
255
	    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
256
	    "version": [2021, 11, 10],
257
	    "description": "causes apple to get greeted on Hydrillabugs issue tracker",
258
	    "payloads": [
259
		{
260
		    "pattern": "https://hydrillabugs.koszko.org/***",
261
		    "payload": "helloapple"
262
		},
263
		{
264
		    "pattern": "https://hachettebugs.koszko.org/***",
265
		    "payload": "helloapple"
266
		}
267
	    ]
268
	}, {
269
	    "type": "license",
270
	    "identifier": "CC0-1.0",
271
	    "long_name": "Creative Commons Zero v1.0 Universal",
272
            "revision": 1,
273
	    "legal_text": [
274
		{
275
		    "format": "text/plain",
276
		    "file":   "cc0.txt"
277
		}
278
	    ]
279
	}
280
    ]
281
}
282
```
283
284
Alternatively, "/index.json" can be appended to the URL to obtain the original index.json, possibly with "//" comments and values like "auto" in some fields.