web/src/pages/api/index.astro
325 lines · 7452 bytes
1---
2import Layout from '@layouts/Layout.astro';
3import Main from '@components/scafold/MainCard.astro';
4import { apiBase } from '@utils/api-config';
5
6const examples = [
7 {
8 label: 'Browse',
9 path: '/v1/categories',
10 response: `{
11 "data": [
12 {
13 "name": "Essentials",
14 "slug": "essentials",
15 "sections": [
16 { "name": "Password Managers", "slug": "password-managers" },
17 { "name": "Browsers", "slug": "browsers" },
18 …
19 ]
20 },
21 …
22 ]
23}`,
24 },
25 {
26 label: 'Lookup',
27 path: '/v1/services/bitwarden',
28 response: `{
29 "data": {
30 "name": "Bitwarden",
31 "url": "https://bitwarden.com",
32 "category": "Essentials",
33 "section": "Password Managers",
34 "github": "bitwarden/server"
35 }
36}`,
37 },
38 {
39 label: 'Search',
40 path: '/v1/search?q=vpn',
41 response: `{
42 "data": [
43 {
44 "slug": "ovpn",
45 "name": "OVPN",
46 "section": "Virtual Private Networks",
47 "score": 15.29
48 }
49 ],
50 "pagination": { "page": 1, "limit": 20, "total": 14 }
51}`,
52 },
53];
54
55const endpoints = [
56 {
57 title: 'Listing data',
58 routes: [
59 ['/v1/services', 'Every service, paginated'],
60 ['/v1/services/{slug}', 'A single service'],
61 ['/v1/categories', 'All categories'],
62 ['/v1/categories/{slug}', 'One category and its sections'],
63 ['/v1/sections/{slug}', 'One section and its services'],
64 ['/v1/search', 'Ranked search across every listing'],
65 ['/v1/stats', 'Totals for the whole list'],
66 ['/v1/health', 'Uptime and data freshness'],
67 ],
68 },
69 {
70 title: 'Enrichment',
71 routes: [
72 ['/v1/enrich/privacy/{tosdrId}', 'ToS;DR rating and policy points'],
73 ['/v1/enrich/security/{owner}/{repo}', 'OSSF scorecard and advisories'],
74 ['/v1/enrich/github/{owner}/{repo}', 'Repo health, license and activity'],
75 ['/v1/enrich/android/{pkg}', 'Trackers, permissions, de-Googled support'],
76 ['/v1/enrich/ios/{bundleId}', 'Version, size and reviews'],
77 ['/v1/enrich/docker/{name}', 'Image tags and pull stats'],
78 ['/v1/enrich/website', 'Hosting, DNS and security posture'],
79 ['/v1/enrich/trackers', 'Third-party trackers a website loads'],
80 ['/v1/enrich/discord/{invite}', 'Server size and activity'],
81 ],
82 },
83];
84
85const source = 'https://github.com/Lissy93/awesome-privacy/tree/main/api';
86---
87
88<Layout
89 title="API | Awesome Privacy"
90 description="A free, no-auth, CORS-enabled REST API for browsing Awesome Privacy's data programmatically, plus enrichment endpoints for trackers, audits and repo health."
91 breadcrumbs={[{ name: 'API', item: 'api' }]}
92>
93 <Main>
94 <div class="api-page">
95 <h1 class="page-title">API</h1>
96 <p class="intro">
97 Every listing on Awesome Privacy is available through our REST API.
98 Browse categories, sections and services, and use the enrichment
99 endpoints to get additional context.
100 </p>
101 <p class="intro">
102 The API is used to power this website, as well as the weekly listing
103 audit and run some preliminary checks on new PRs.
104 </p>
105
106 <div class="links">
107 <a class="primary" href={`${apiBase}/docs`}>Read the docs</a>
108 <a href={source}>View source</a>
109 </div>
110
111 <div class="example" role="group" aria-label="Example requests">
112 {
113 examples.map((_, index) => (
114 <input
115 type="radio"
116 name="example"
117 id={`example-${index}`}
118 checked={index === 0}
119 />
120 ))
121 }
122 <div class="tabs">
123 {
124 examples.map(({ label }, index) => (
125 <label for={`example-${index}`}>{label}</label>
126 ))
127 }
128 </div>
129 <div class="panels">
130 {
131 examples.map(({ path, response }) => (
132 <div class="panel">
133 <div class="request">
134 <span class="method">GET</span>
135 <a href={apiBase + path}>{apiBase + path}</a>
136 </div>
137 <pre>{response}</pre>
138 </div>
139 ))
140 }
141 </div>
142 </div>
143
144 <div class="endpoints">
145 {
146 endpoints.map((group) => (
147 <section>
148 <h2>{group.title}</h2>
149 <ul>
150 {group.routes.map(([path, summary]) => (
151 <li>
152 <code>{path}</code>
153 <span>{summary}</span>
154 </li>
155 ))}
156 </ul>
157 </section>
158 ))
159 }
160 </div>
161 </div>
162 </Main>
163</Layout>
164
165<style lang="scss">
166 $tab-count: 3;
167
168 .api-page {
169 max-width: 45rem;
170 margin: 0 auto;
171 padding-bottom: var(--space-md);
172 }
173
174 .intro {
175 font-size: var(--text-md);
176 opacity: var(--opacity-subtle);
177 }
178
179 .links {
180 display: flex;
181 flex-wrap: wrap;
182 align-items: center;
183 gap: var(--space-md);
184 font-family: var(--font-subtitle);
185 a {
186 color: var(--accent-3-text);
187 &:hover {
188 color: var(--accent-text);
189 }
190 }
191 .primary {
192 padding: var(--space-sm) var(--space-md);
193 border: var(--border-light);
194 border-radius: var(--curve-pill);
195 box-shadow: var(--shadow-sm);
196 background: var(--accent);
197 color: var(--accent-fg);
198 font-weight: bold;
199 text-decoration: none;
200 transition: var(--transition-normal);
201 &:hover {
202 box-shadow: var(--shadow-sm-hover);
203 color: var(--accent-fg);
204 }
205 }
206 }
207
208 .example {
209 margin-top: var(--space-lg);
210 border: var(--border-heavy);
211 border-radius: var(--curve-sm);
212 box-shadow: var(--shadow-md);
213 background: var(--background-form);
214 overflow: hidden;
215 input {
216 position: absolute;
217 opacity: 0;
218 pointer-events: none;
219 }
220 @media (max-width: 428px) {
221 display: none;
222 }
223 }
224
225 .tabs {
226 display: flex;
227 border-bottom: var(--border-heavy);
228 background: var(--surface);
229 label {
230 padding: var(--space-sm) var(--space-md);
231 border-right: var(--border-light);
232 color: var(--foreground);
233 opacity: var(--opacity-muted);
234 cursor: pointer;
235 font-family: var(--font-subtitle);
236 font-size: var(--text-sm);
237 transition: var(--transition-normal);
238 &:hover {
239 opacity: 1;
240 }
241 }
242 }
243
244 .panel {
245 display: none;
246 }
247
248 @for $i from 1 through $tab-count {
249 input:nth-of-type(#{$i}):checked ~ .panels .panel:nth-child(#{$i}) {
250 display: block;
251 }
252 input:nth-of-type(#{$i}):checked ~ .tabs label:nth-child(#{$i}) {
253 opacity: 1;
254 background: var(--accent-3);
255 color: var(--accent-3-fg);
256 font-weight: bold;
257 }
258 input:nth-of-type(#{$i}):focus-visible ~ .tabs label:nth-child(#{$i}) {
259 outline: 2px solid var(--accent-text);
260 outline-offset: -2px;
261 }
262 }
263
264 .request {
265 display: flex;
266 align-items: center;
267 gap: var(--space-sm);
268 padding: var(--space-sm) var(--space-md);
269 border-bottom: var(--border-light);
270 font-family: var(--font-code);
271 font-size: var(--text-sm);
272 .method {
273 padding: 0.1rem var(--space-xs);
274 border-radius: var(--curve-sm);
275 background: var(--accent-3);
276 color: var(--accent-3-fg);
277 font-weight: bold;
278 }
279 a {
280 color: var(--foreground);
281 overflow-wrap: anywhere;
282 &:hover {
283 color: var(--accent-text);
284 }
285 }
286 }
287
288 pre {
289 margin: 0;
290 padding: var(--space-md);
291 overflow-x: auto;
292 font-family: var(--font-code);
293 font-size: var(--text-sm);
294 }
295
296 .endpoints {
297 display: grid;
298 grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
299 gap: var(--space-lg);
300 margin-top: var(--space-lg);
301 h2 {
302 margin: 0 0 var(--space-sm);
303 font-size: var(--text-md);
304 }
305 ul {
306 margin: 0;
307 padding: 0;
308 list-style: none;
309 }
310 li {
311 display: flex;
312 flex-direction: column;
313 margin-bottom: var(--space-sm);
314 }
315 code {
316 font-family: var(--font-code);
317 font-size: var(--text-sm);
318 overflow-wrap: anywhere;
319 }
320 span {
321 font-size: var(--text-sm);
322 opacity: var(--opacity-muted);
323 }
324 }
325</style>