Project

General

Profile

Repository API » History » Version 21

koszko, 02/10/2022 07:04 PM
Reflect recent major updates to repository API

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 21 koszko
Also, once we get to do the redesign discussed in [this forum thread](/boards/1/topics/56), current interface will be replaced with the one described below (although some changes are still possible to happen!). In the examples below we assume base URL of the API server is `https://hydrilla.example.com/`.
65 5 koszko
66 1 jahoti
### Fetching resource info
67 4 koszko
"resource" is now the equivalent of what we used to call "bag".
68 1 jahoti
69 21 koszko
Let's assume we want to retrieve the definition of resource `helloapple`. We can issue a GET to `https://hydrilla.example.com/resource/helloapple.json`. It returns:
70 1 jahoti
``` javascript
71 4 koszko
{
72 21 koszko
    "api_schema_version": [
73
        1
74
    ],
75 14 koszko
    "source_name": "hello",
76 1 jahoti
    "source_copyright": [
77 21 koszko
        {
78
            "file": "report.spdx",
79
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
80
        },
81
        {
82
            "file": "LICENSES/CC0-1.0.txt",
83
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
84
        }
85 1 jahoti
    ],
86
    "type": "resource",
87
    "identifier": "helloapple",
88
    "long_name": "Hello Apple",
89 14 koszko
    "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68",
90 21 koszko
    "version": [
91
        2021,
92
        11,
93
        10
94
    ],
95 12 koszko
    "revision": 1,
96
    "description": "greets an apple",
97 21 koszko
    "dependencies": [
98
        {
99
            "identifier": "hello-message"
100
        }
101
    ],
102 1 jahoti
    "scripts": [
103
        {
104
            "file": "hello.js",
105 21 koszko
            "sha256": "18dd7d7ac9f74a5ba871791ac6aa4d55530a336ae1b373538b6dd5320b330414"
106
        },
107
        {
108 1 jahoti
            "file": "bye.js",
109 21 koszko
            "sha256": "cee8d88cf5e5346522fd9ee5e1f994b335fb68d2f460b27b2a2a05f0bcd2b55b"
110 1 jahoti
        }
111
    ]
112
}
113
```
114
115 21 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 including version in the GET request. Requested path should then take the form `/resource/<resource_name>/<version>` (e.g. `GET https://hydrilla.example.com/resource/helloapple/2021.11.9`).
116 1 jahoti
117 21 koszko
File can be retrieved by issuing a GET request to `https://hydrilla.example.com/file/sha256/<file's_sha256_sum>`. For example, requests to `https://hydrilla.example.com/file/sha256/a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499` and `hydrilla.example.com/file/sha256/18dd7d7ac9f74a5ba871791ac6aa4d55530a336ae1b373538b6dd5320b330414` yield contents of `LICENSES/CC0-1.0.txt` and `hello.js`, respectively.)
118
119
A [JSON schema](https://json-schema.org) describing resource definition format is available [here](https://hydrilla.koszko.org/schemas/api_resource_description-1.schema.json).
120
121 14 koszko
### Fetching mapping info
122
"mapping" is now a set of what we used to call "pattern".
123
124 21 koszko
Let's assume we want to retrieve the definition of mapping `helloapple` (mapping is allowed to have the same identifier as a resource). We can issue a GET to `https://hydrilla.example.com/mapping/helloapple.json`. It returns:
125 14 koszko
``` javascript
126 1 jahoti
{
127 21 koszko
    "api_schema_version": [
128
        1
129
    ],
130
    "source_name": "hello",
131 1 jahoti
    "source_copyright": [
132 21 koszko
        {
133
            "file": "report.spdx",
134
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
135
        },
136
        {
137
            "file": "LICENSES/CC0-1.0.txt",
138
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
139
        }
140 1 jahoti
    ],
141
    "type": "mapping",
142 21 koszko
    "identifier": "helloapple",
143
    "long_name": "Hello Apple",
144 1 jahoti
    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
145 21 koszko
    "version": [
146
        2021,
147
        11,
148
        10
149
    ],
150
    "description": "causes apple to get greeted on Hydrillabugs issue tracker",
151 14 koszko
    "payloads": {
152 21 koszko
        "https://hydrillabugs.koszko.org/***": {
153
            "identifier": "helloapple"
154 1 jahoti
        },
155 21 koszko
        "https://hachettebugs.koszko.org/***": {
156
            "identifier": "helloapple"
157 1 jahoti
        }
158
    }
159
}
160
```
161 21 koszko
or 404 Not Found in case `helloapple` mapping does not exist. If multiple versions are available, newest version's JSON description gets returned. A different one can be retrieved by including version in the GET request. Requested path should then take the form `/mapping/<mapping_name>/<version>` (e.g. `GET https://hydrilla.example.com/mapping/helloapple/2021.11.8`).
162 1 jahoti
163 21 koszko
File can be retrieved by issuing a GET request to `https://hydrilla.example.com/file/sha256/<file's_sha256_sum>`. For example, request to `https://hydrilla.example.com/file/sha256/a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499` yields contents of `LICENSES/CC0-1.0.txt`.
164
165
A [JSON schema](https://json-schema.org) describing mapping definition format is available [here](https://hydrilla.koszko.org/schemas/api_mapping_description-1.schema.json).
166
167 18 koszko
### Querying mappings that match given URL
168 21 koszko
Assume we want to query mappings with patterns matching `https://example.org/a/b`. We can issue a GET to `https://hydrilla.example.com/query?url=https://example.org/a/b`. It returns:
169 1 jahoti
``` javascript
170
{
171 21 koszko
    "api_schema_version": [
172
        1
173
    ],
174 1 jahoti
    "mappings": [
175
        {
176
            "identifier": "example-org-minimal",
177
            "long_name": "Example.org Minimal",
178 21 koszko
            "version": [
179
                2022,
180
                5,
181
                10
182
            ]
183
        },
184
        {
185 1 jahoti
            "identifier": "example-org-experimental",
186
            "long_name": "example.org fix bundle",
187 21 koszko
            "version": [
188
                0,
189
                4
190
            ]
191 20 koszko
        }
192 16 koszko
    ]
193 21 koszko
}
194 16 koszko
```
195 1 jahoti
196 16 koszko
The value of "mappings" can be an empty array (`[]`) in case no mappings match given URL. In case many versions of some mapping match the URL, only the most current of those versions that do is listed. In case the URL is of wrong format, 400 Bad Request is returned.
197 14 koszko
198 21 koszko
A [JSON schema](https://json-schema.org) describing query result format is available [here](https://hydrilla.koszko.org/schemas/api_query_result-1.schema.json).
199
200 12 koszko
### Fetching source info
201
By "source" we mean description of a source package used to build Hydrilla site content.
202
203 21 koszko
Assume we want to get description of source package `hello`. We can issue a GET to `https://hydrilla.example.com/source/hello.json`. It returns:
204 12 koszko
``` javascript
205
{
206 21 koszko
    "api_schema_version": [
207
        1
208
    ],
209 12 koszko
    "source_name": "hello",
210
    "source_copyright": [
211 21 koszko
        {
212
            "file": "report.spdx",
213
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
214
        },
215
        {
216
            "file": "LICENSES/CC0-1.0.txt",
217
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
218
        }
219 14 koszko
    ],
220 21 koszko
    "source_archives": {
221
        "zip": {
222
            "sha256": "f61bfc5594a2603452a8c8e5f7a3f36f255bc39d5ffea02c9fdefc0de6461c74"
223
        }
224
    },
225
    "upstream_url": "https://git.koszko.org/hydrilla-source-package-example",
226 14 koszko
    "definitions": [
227 12 koszko
        {
228
            "type": "resource",
229
            "identifier": "helloapple",
230 21 koszko
            "long_name": "Hello Apple",
231
            "version": [
232
                2021,
233
                11,
234
                10
235
            ]
236
        },
237
        {
238
            "type": "resource",
239 12 koszko
            "identifier": "hello-message",
240 21 koszko
            "long_name": "Hello Message",
241
            "version": [
242
                2021,
243
                11,
244
                10
245
            ]
246
        },
247
        {
248 14 koszko
            "type": "mapping",
249 1 jahoti
            "identifier": "helloapple",
250 21 koszko
            "long_name": "Hello Apple",
251
            "version": [
252
                2021,
253
                11,
254
                10
255
            ]
256 1 jahoti
        }
257
    ]
258
}
259
```
260
261 21 koszko
Or 404 Not Found in case no such source package exists. Here `zip` was listed among available source archive extensions. It means we can download the zip archive of this source package by issuing GET to `https://hydrilla.example.com/source/hello.zip`.
262 1 jahoti
263
With api_schema_version beginning with major number 1, zip archive is always guaranteed to be available.
264 21 koszko
265
A [JSON schema](https://json-schema.org) describing source package description format is available [here](https://hydrilla.koszko.org/schemas/api_source_description-1.schema.json).