Project

General

Profile

Repository API » History » Version 25

koszko, 06/17/2022 08:45 PM
update current API and schema versions

1 1 jahoti
# Repository API
2
3 25 koszko
*Note: you can try using a live Hydrilla instance at [https://hydrilla.koszko.org/api_v2](https://hydrilla.koszko.org/api_v2); try pasting this into the URL bar: [https://hydrilla.koszko.org/api_v2/query?url=https://opencores.org/projects](https://hydrilla.koszko.org/api_v2/query?url=https://opencores.org/projects)*
4 23 koszko
5 1 jahoti
{{toc}}
6
7 23 koszko
## Fetching resource info
8
"resource" is now the equivalent of what we used to call "bag" in Haketilo 0.1.
9 1 jahoti
10 4 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:
11 1 jahoti
``` javascript
12 21 koszko
{
13 25 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_resource_description-1.schema.json",
14 4 koszko
    "source_name": "hello",
15 22 koszko
    "source_copyright": [
16 14 koszko
        {
17 1 jahoti
            "file": "report.spdx",
18 21 koszko
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
19
        },
20
        {
21
            "file": "LICENSES/CC0-1.0.txt",
22
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
23
        }
24
    ],
25
    "type": "resource",
26 1 jahoti
    "identifier": "helloapple",
27
    "long_name": "Hello Apple",
28
    "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68",
29
    "version": [
30 14 koszko
        2021,
31 21 koszko
        11,
32
        10
33
    ],
34
    "revision": 1,
35
    "description": "greets an apple",
36 12 koszko
    "dependencies": [
37
        {
38 21 koszko
            "identifier": "hello-message"
39
        }
40
    ],
41 1 jahoti
    "scripts": [
42 21 koszko
        {
43
            "file": "hello.js",
44 1 jahoti
            "sha256": "18dd7d7ac9f74a5ba871791ac6aa4d55530a336ae1b373538b6dd5320b330414"
45
        },
46
        {
47 21 koszko
            "file": "bye.js",
48
            "sha256": "cee8d88cf5e5346522fd9ee5e1f994b335fb68d2f460b27b2a2a05f0bcd2b55b"
49
        }
50 1 jahoti
    ]
51 21 koszko
}
52 1 jahoti
```
53
54
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`).
55
56
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.)
57 21 koszko
58 25 koszko
A [JSON schema](https://json-schema.org) describing resource definition format is available [here](https://hydrilla.koszko.org/schemas/api_resource_description-2.schema.json).
59 21 koszko
60 23 koszko
## Fetching mapping info
61
"mapping" is now a set of what we used to call "pattern" in Haketilo 0.1.
62 14 koszko
63
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:
64 1 jahoti
``` javascript
65 21 koszko
{
66 25 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_mapping_description-2.schema.json",
67 22 koszko
    "source_name": "hello",
68 21 koszko
    "source_copyright": [
69 1 jahoti
        {
70
            "file": "report.spdx",
71
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
72 21 koszko
        },
73
        {
74
            "file": "LICENSES/CC0-1.0.txt",
75
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
76
        }
77
    ],
78
    "type": "mapping",
79
    "identifier": "helloapple",
80 1 jahoti
    "long_name": "Hello Apple",
81
    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
82 21 koszko
    "version": [
83
        2021,
84 1 jahoti
        11,
85 21 koszko
        10
86
    ],
87
    "description": "causes apple to get greeted on Hydrillabugs issue tracker",
88
    "payloads": {
89
        "https://hydrillabugs.koszko.org/***": {
90
            "identifier": "helloapple"
91 14 koszko
        },
92 21 koszko
        "https://hachettebugs.koszko.org/***": {
93
            "identifier": "helloapple"
94 1 jahoti
        }
95 21 koszko
    }
96
}
97 1 jahoti
```
98
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`).
99
100 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`.
101 1 jahoti
102 25 koszko
A [JSON schema](https://json-schema.org) describing mapping definition format is available [here](https://hydrilla.koszko.org/schemas/api_mapping_description-2.schema.json).
103 21 koszko
104 23 koszko
## Querying mappings that match given URL
105 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:
106
``` javascript
107 18 koszko
{
108 25 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_query_result-2.schema.json",
109 21 koszko
    "mappings": [
110 22 koszko
        {
111 1 jahoti
            "identifier": "example-org-minimal",
112
            "long_name": "Example.org Minimal",
113
            "version": [
114
                2022,
115 21 koszko
                5,
116
                10
117
            ]
118
        },
119
        {
120
            "identifier": "example-org-experimental",
121
            "long_name": "example.org fix bundle",
122 1 jahoti
            "version": [
123
                0,
124 21 koszko
                4
125
            ]
126
        }
127
    ]
128
}
129 16 koszko
```
130 1 jahoti
131 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.
132 1 jahoti
133 25 koszko
A [JSON schema](https://json-schema.org) describing query result format is available [here](https://hydrilla.koszko.org/schemas/api_query_result-2.schema.json).
134 21 koszko
135 23 koszko
## Fetching source info
136
By "source" we mean description of a source package used to build Hydrilla packages.
137 12 koszko
138
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:
139 21 koszko
``` javascript
140
{
141 25 koszko
    "$schema": "https://hydrilla.koszko.org/schemas/api_source_description-2.schema.json",
142 12 koszko
    "source_name": "hello",
143
    "source_copyright": [
144 21 koszko
        {
145
            "file": "report.spdx",
146
            "sha256": "249599a36ad9f6f33b8bf16ca6ace2413d95d8cdb481173968fa4e97fd0a5635"
147
        },
148
        {
149
            "file": "LICENSES/CC0-1.0.txt",
150
            "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
151
        }
152 14 koszko
    ],
153 21 koszko
    "source_archives": {
154
        "zip": {
155
            "sha256": "f61bfc5594a2603452a8c8e5f7a3f36f255bc39d5ffea02c9fdefc0de6461c74"
156
        }
157
    },
158
    "upstream_url": "https://git.koszko.org/hydrilla-source-package-example",
159 14 koszko
    "definitions": [
160 12 koszko
        {
161
            "type": "resource",
162
            "identifier": "helloapple",
163 21 koszko
            "long_name": "Hello Apple",
164
            "version": [
165
                2021,
166
                11,
167
                10
168
            ]
169
        },
170
        {
171
            "type": "resource",
172 12 koszko
            "identifier": "hello-message",
173 21 koszko
            "long_name": "Hello Message",
174
            "version": [
175
                2021,
176
                11,
177
                10
178
            ]
179
        },
180
        {
181 14 koszko
            "type": "mapping",
182 1 jahoti
            "identifier": "helloapple",
183 21 koszko
            "long_name": "Hello Apple",
184 1 jahoti
            "version": [
185 21 koszko
                2021,
186
                11,
187
                10
188
            ]
189
        }
190 1 jahoti
    ]
191
}
192
```
193
194 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`.
195 1 jahoti
196 22 koszko
With schema version beginning with major number 1, zip archive is always guaranteed to be available.
197 21 koszko
198 25 koszko
A [JSON schema](https://json-schema.org) describing source package description format is available [here](https://hydrilla.koszko.org/schemas/api_source_description-2.schema.json).