Project

General

Profile

Repository API » History » Version 22

koszko, 02/14/2022 11:19 AM
specify full schema URL in instances

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 22 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_resource_description-1.schema.json",
73 14 koszko
    "source_name": "hello",
74 1 jahoti
    "source_copyright": [
75 21 koszko
        {
76
            "file": "report.spdx",
77
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
78
        },
79
        {
80
            "file": "LICENSES/CC0-1.0.txt",
81
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
82
        }
83 1 jahoti
    ],
84
    "type": "resource",
85
    "identifier": "helloapple",
86
    "long_name": "Hello Apple",
87 14 koszko
    "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68",
88 21 koszko
    "version": [
89
        2021,
90
        11,
91
        10
92
    ],
93 12 koszko
    "revision": 1,
94
    "description": "greets an apple",
95 21 koszko
    "dependencies": [
96
        {
97
            "identifier": "hello-message"
98
        }
99
    ],
100 1 jahoti
    "scripts": [
101
        {
102
            "file": "hello.js",
103 21 koszko
            "sha256": "18dd7d7ac9f74a5ba871791ac6aa4d55530a336ae1b373538b6dd5320b330414"
104
        },
105
        {
106 1 jahoti
            "file": "bye.js",
107 21 koszko
            "sha256": "cee8d88cf5e5346522fd9ee5e1f994b335fb68d2f460b27b2a2a05f0bcd2b55b"
108 1 jahoti
        }
109
    ]
110
}
111
```
112
113 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`).
114 1 jahoti
115 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.)
116
117
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).
118
119 14 koszko
### Fetching mapping info
120
"mapping" is now a set of what we used to call "pattern".
121
122 1 jahoti
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:
123 21 koszko
``` javascript
124
{
125 22 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_mapping_description-1.schema.json",
126 21 koszko
    "source_name": "hello",
127 1 jahoti
    "source_copyright": [
128 21 koszko
        {
129
            "file": "report.spdx",
130
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
131
        },
132
        {
133
            "file": "LICENSES/CC0-1.0.txt",
134
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
135
        }
136 1 jahoti
    ],
137
    "type": "mapping",
138 21 koszko
    "identifier": "helloapple",
139
    "long_name": "Hello Apple",
140 1 jahoti
    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
141 21 koszko
    "version": [
142
        2021,
143
        11,
144
        10
145
    ],
146
    "description": "causes apple to get greeted on Hydrillabugs issue tracker",
147 14 koszko
    "payloads": {
148 21 koszko
        "https://hydrillabugs.koszko.org/***": {
149
            "identifier": "helloapple"
150 1 jahoti
        },
151 21 koszko
        "https://hachettebugs.koszko.org/***": {
152
            "identifier": "helloapple"
153 1 jahoti
        }
154
    }
155
}
156
```
157 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`).
158 1 jahoti
159 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`.
160
161 1 jahoti
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).
162 21 koszko
163
### Querying mappings that match given URL
164 18 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:
165 21 koszko
``` javascript
166
{
167 22 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_query_result-1.schema.json",
168 1 jahoti
    "mappings": [
169
        {
170
            "identifier": "example-org-minimal",
171
            "long_name": "Example.org Minimal",
172 21 koszko
            "version": [
173
                2022,
174
                5,
175
                10
176
            ]
177
        },
178
        {
179 1 jahoti
            "identifier": "example-org-experimental",
180
            "long_name": "example.org fix bundle",
181 21 koszko
            "version": [
182
                0,
183
                4
184
            ]
185 20 koszko
        }
186 16 koszko
    ]
187 21 koszko
}
188 16 koszko
```
189 1 jahoti
190 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.
191 1 jahoti
192 14 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).
193 21 koszko
194
### Fetching source info
195 12 koszko
By "source" we mean description of a source package used to build Hydrilla site content.
196
197
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:
198 21 koszko
``` javascript
199
{
200 22 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_source_description-1.schema.json",
201 12 koszko
    "source_name": "hello",
202
    "source_copyright": [
203 21 koszko
        {
204
            "file": "report.spdx",
205
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
206
        },
207
        {
208
            "file": "LICENSES/CC0-1.0.txt",
209
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
210
        }
211 14 koszko
    ],
212 21 koszko
    "source_archives": {
213
        "zip": {
214
            "sha256": "f61bfc5594a2603452a8c8e5f7a3f36f255bc39d5ffea02c9fdefc0de6461c74"
215
        }
216
    },
217
    "upstream_url": "https://git.koszko.org/hydrilla-source-package-example",
218 14 koszko
    "definitions": [
219 12 koszko
        {
220
            "type": "resource",
221
            "identifier": "helloapple",
222 21 koszko
            "long_name": "Hello Apple",
223
            "version": [
224
                2021,
225
                11,
226
                10
227
            ]
228
        },
229
        {
230
            "type": "resource",
231 12 koszko
            "identifier": "hello-message",
232 21 koszko
            "long_name": "Hello Message",
233
            "version": [
234
                2021,
235
                11,
236
                10
237
            ]
238
        },
239
        {
240 14 koszko
            "type": "mapping",
241 1 jahoti
            "identifier": "helloapple",
242 21 koszko
            "long_name": "Hello Apple",
243 1 jahoti
            "version": [
244 21 koszko
                2021,
245
                11,
246
                10
247
            ]
248
        }
249 1 jahoti
    ]
250
}
251
```
252
253 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`.
254 1 jahoti
255 22 koszko
With schema version beginning with major number 1, zip archive is always guaranteed to be available.
256 21 koszko
257
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).