Commit e9479925a2
Unsigned
Layout: unified · split
web/src/pages/api/index.astro +312 −35
| @@ -1,47 +1,324 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | import Layout from '@layouts/Layout.astro'; |
| 3 | import Button from '@components/form/Button.astro'; | |
| 3 | import Main from '@components/scafold/MainCard.astro'; | |
| 4 | import { apiBase } from '@utils/api-config'; | |
| 4 | 5 | |
| 5 | import MainCard from '@components/scafold/MainCard.astro'; | |
| 6 | const 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 | ||
| 55 | const 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/discord/{invite}', 'Server size and activity'], | |
| 80 | ], | |
| 81 | }, | |
| 82 | ]; | |
| 83 | ||
| 84 | const source = 'https://github.com/Lissy93/awesome-privacy/tree/main/api'; | |
| 6 | 85 | --- |
| 7 | 86 | |
| 8 | <Layout title="API Docs | Awesome Privacy"> | |
| 9 | <MainCard> | |
| 10 | <div id="swagger-ui"></div> | |
| 11 | <div class="go"> | |
| 12 | <Button url="https://api.awesome-privacy.xyz" text="Try it Out" /> | |
| 87 | <Layout | |
| 88 | title="API | Awesome Privacy" | |
| 89 | 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." | |
| 90 | breadcrumbs={[{ name: 'API', item: 'api' }]} | |
| 91 | > | |
| 92 | <Main> | |
| 93 | <div class="api-page"> | |
| 94 | <h1 class="page-title">API</h1> | |
| 95 | <p class="intro"> | |
| 96 | Every listing on Awesome Privacy is available through our REST API. | |
| 97 | Browse categories, sections and services, and use the enrichment | |
| 98 | endpoints to get additional context. | |
| 99 | </p> | |
| 100 | <p class="intro"> | |
| 101 | The API is used to power this website, as well as the weekly listing | |
| 102 | audit and run some preliminary checks on new PRs. | |
| 103 | </p> | |
| 104 | ||
| 105 | <div class="links"> | |
| 106 | <a class="primary" href={`${apiBase}/docs`}>Read the docs</a> | |
| 107 | <a href={source}>View source</a> | |
| 108 | </div> | |
| 109 | ||
| 110 | <div class="example" role="group" aria-label="Example requests"> | |
| 111 | { | |
| 112 | examples.map((_, index) => ( | |
| 113 | <input | |
| 114 | type="radio" | |
| 115 | name="example" | |
| 116 | id={`example-${index}`} | |
| 117 | checked={index === 0} | |
| 118 | /> | |
| 119 | )) | |
| 120 | } | |
| 121 | <div class="tabs"> | |
| 122 | { | |
| 123 | examples.map(({ label }, index) => ( | |
| 124 | <label for={`example-${index}`}>{label}</label> | |
| 125 | )) | |
| 126 | } | |
| 127 | </div> | |
| 128 | <div class="panels"> | |
| 129 | { | |
| 130 | examples.map(({ path, response }) => ( | |
| 131 | <div class="panel"> | |
| 132 | <div class="request"> | |
| 133 | <span class="method">GET</span> | |
| 134 | <a href={apiBase + path}>{apiBase + path}</a> | |
| 135 | </div> | |
| 136 | <pre>{response}</pre> | |
| 137 | </div> | |
| 138 | )) | |
| 139 | } | |
| 140 | </div> | |
| 141 | </div> | |
| 142 | ||
| 143 | <div class="endpoints"> | |
| 144 | { | |
| 145 | endpoints.map((group) => ( | |
| 146 | <section> | |
| 147 | <h2>{group.title}</h2> | |
| 148 | <ul> | |
| 149 | {group.routes.map(([path, summary]) => ( | |
| 150 | <li> | |
| 151 | <code>{path}</code> | |
| 152 | <span>{summary}</span> | |
| 153 | </li> | |
| 154 | ))} | |
| 155 | </ul> | |
| 156 | </section> | |
| 157 | )) | |
| 158 | } | |
| 159 | </div> | |
| 13 | 160 | </div> |
| 14 | </MainCard> | |
| 161 | </Main> | |
| 15 | 162 | </Layout> |
| 16 | 163 | |
| 17 | <link | |
| 18 | rel="stylesheet" | |
| 19 | type="text/css" | |
| 20 | href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui.css" | |
| 21 | /> | |
| 22 | <script | |
| 23 | is:inline | |
| 24 | src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui-bundle.js" | |
| 25 | ></script> | |
| 26 | <script type="module" is:inline> | |
| 27 | window.onload = () => { | |
| 28 | SwaggerUIBundle({ | |
| 29 | url: 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/api/open-api-spec.yml', | |
| 30 | dom_id: '#swagger-ui', | |
| 31 | deepLinking: true, | |
| 32 | presets: [ | |
| 33 | SwaggerUIBundle.presets.apis, | |
| 34 | SwaggerUIBundle.SwaggerUIStandalonePreset, | |
| 35 | ], | |
| 36 | plugins: [SwaggerUIBundle.plugins.DownloadUrl], | |
| 37 | }); | |
| 38 | }; | |
| 39 | </script> | |
| 40 | ||
| 41 | 164 | <style lang="scss"> |
| 42 | .go { | |
| 165 | $tab-count: 3; | |
| 166 | ||
| 167 | .api-page { | |
| 168 | max-width: 45rem; | |
| 169 | margin: 0 auto; | |
| 170 | padding-bottom: var(--space-md); | |
| 171 | } | |
| 172 | ||
| 173 | .intro { | |
| 174 | font-size: var(--text-md); | |
| 175 | opacity: var(--opacity-subtle); | |
| 176 | } | |
| 177 | ||
| 178 | .links { | |
| 43 | 179 | display: flex; |
| 44 | justify-content: center; | |
| 45 | margin-top: 1rem; | |
| 180 | flex-wrap: wrap; | |
| 181 | align-items: center; | |
| 182 | gap: var(--space-md); | |
| 183 | font-family: var(--font-subtitle); | |
| 184 | a { | |
| 185 | color: var(--accent-3-text); | |
| 186 | &:hover { | |
| 187 | color: var(--accent-text); | |
| 188 | } | |
| 189 | } | |
| 190 | .primary { | |
| 191 | padding: var(--space-sm) var(--space-md); | |
| 192 | border: var(--border-light); | |
| 193 | border-radius: var(--curve-pill); | |
| 194 | box-shadow: var(--shadow-sm); | |
| 195 | background: var(--accent); | |
| 196 | color: var(--accent-fg); | |
| 197 | font-weight: bold; | |
| 198 | text-decoration: none; | |
| 199 | transition: var(--transition-normal); | |
| 200 | &:hover { | |
| 201 | box-shadow: var(--shadow-sm-hover); | |
| 202 | color: var(--accent-fg); | |
| 203 | } | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | .example { | |
| 208 | margin-top: var(--space-lg); | |
| 209 | border: var(--border-heavy); | |
| 210 | border-radius: var(--curve-sm); | |
| 211 | box-shadow: var(--shadow-md); | |
| 212 | background: var(--background-form); | |
| 213 | overflow: hidden; | |
| 214 | input { | |
| 215 | position: absolute; | |
| 216 | opacity: 0; | |
| 217 | pointer-events: none; | |
| 218 | } | |
| 219 | @media (max-width: 428px) { | |
| 220 | display: none; | |
| 221 | } | |
| 222 | } | |
| 223 | ||
| 224 | .tabs { | |
| 225 | display: flex; | |
| 226 | border-bottom: var(--border-heavy); | |
| 227 | background: var(--surface); | |
| 228 | label { | |
| 229 | padding: var(--space-sm) var(--space-md); | |
| 230 | border-right: var(--border-light); | |
| 231 | color: var(--foreground); | |
| 232 | opacity: var(--opacity-muted); | |
| 233 | cursor: pointer; | |
| 234 | font-family: var(--font-subtitle); | |
| 235 | font-size: var(--text-sm); | |
| 236 | transition: var(--transition-normal); | |
| 237 | &:hover { | |
| 238 | opacity: 1; | |
| 239 | } | |
| 240 | } | |
| 241 | } | |
| 242 | ||
| 243 | .panel { | |
| 244 | display: none; | |
| 245 | } | |
| 246 | ||
| 247 | @for $i from 1 through $tab-count { | |
| 248 | input:nth-of-type(#{$i}):checked ~ .panels .panel:nth-child(#{$i}) { | |
| 249 | display: block; | |
| 250 | } | |
| 251 | input:nth-of-type(#{$i}):checked ~ .tabs label:nth-child(#{$i}) { | |
| 252 | opacity: 1; | |
| 253 | background: var(--accent-3); | |
| 254 | color: var(--accent-3-fg); | |
| 255 | font-weight: bold; | |
| 256 | } | |
| 257 | input:nth-of-type(#{$i}):focus-visible ~ .tabs label:nth-child(#{$i}) { | |
| 258 | outline: 2px solid var(--accent-text); | |
| 259 | outline-offset: -2px; | |
| 260 | } | |
| 261 | } | |
| 262 | ||
| 263 | .request { | |
| 264 | display: flex; | |
| 265 | align-items: center; | |
| 266 | gap: var(--space-sm); | |
| 267 | padding: var(--space-sm) var(--space-md); | |
| 268 | border-bottom: var(--border-light); | |
| 269 | font-family: var(--font-code); | |
| 270 | font-size: var(--text-sm); | |
| 271 | .method { | |
| 272 | padding: 0.1rem var(--space-xs); | |
| 273 | border-radius: var(--curve-sm); | |
| 274 | background: var(--accent-3); | |
| 275 | color: var(--accent-3-fg); | |
| 276 | font-weight: bold; | |
| 277 | } | |
| 278 | a { | |
| 279 | color: var(--foreground); | |
| 280 | overflow-wrap: anywhere; | |
| 281 | &:hover { | |
| 282 | color: var(--accent-text); | |
| 283 | } | |
| 284 | } | |
| 285 | } | |
| 286 | ||
| 287 | pre { | |
| 288 | margin: 0; | |
| 289 | padding: var(--space-md); | |
| 290 | overflow-x: auto; | |
| 291 | font-family: var(--font-code); | |
| 292 | font-size: var(--text-sm); | |
| 293 | } | |
| 294 | ||
| 295 | .endpoints { | |
| 296 | display: grid; | |
| 297 | grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); | |
| 298 | gap: var(--space-lg); | |
| 299 | margin-top: var(--space-lg); | |
| 300 | h2 { | |
| 301 | margin: 0 0 var(--space-sm); | |
| 302 | font-size: var(--text-md); | |
| 303 | } | |
| 304 | ul { | |
| 305 | margin: 0; | |
| 306 | padding: 0; | |
| 307 | list-style: none; | |
| 308 | } | |
| 309 | li { | |
| 310 | display: flex; | |
| 311 | flex-direction: column; | |
| 312 | margin-bottom: var(--space-sm); | |
| 313 | } | |
| 314 | code { | |
| 315 | font-family: var(--font-code); | |
| 316 | font-size: var(--text-sm); | |
| 317 | overflow-wrap: anywhere; | |
| 318 | } | |
| 319 | span { | |
| 320 | font-size: var(--text-sm); | |
| 321 | opacity: var(--opacity-muted); | |
| 322 | } | |
| 46 | 323 | } |
| 47 | 324 | </style> |