🛠️ Refactor API documentation for clarity and consistency; update URLs and TypeScript types

This commit is contained in:
pheralb
2025-09-16 13:24:13 +01:00
parent 3b3d30cd0c
commit f411ffef8a
+54 -51
View File
@@ -11,30 +11,25 @@ SVGL API is a RESTFul API that allows you to get all the information of the SVGs
The API is currently open to everyone and does not require any authentication. However, to prevent abusive use of the API, there is a limit to the number of requests. The API is currently open to everyone and does not require any authentication. However, to prevent abusive use of the API, there is a limit to the number of requests.
Don't use the API for create the same product as SVGL. The API is intended to be used for extensions, plugins, or other tools that can help the community. > Don't use the API for create the same product as SVGL. The API is intended to be used for extensions, plugins, or other tools that can help the community.
## Base URL ## Base URLs
The base URL for the API is: SVGs URL:
```bash ```bash
https://api.svgl.app https://api.svgl.app
# or ```
Categories URL:
```bash
https://api.svgl.app/categories https://api.svgl.app/categories
``` ```
## Typescript usage ## Typescript
- For categories: You can use the following types for the SVG responses:
```ts
export interface Category {
category: string;
total: number;
}
```
- For SVGs:
```ts ```ts
export type ThemeOptions = { export type ThemeOptions = {
@@ -42,27 +37,27 @@ export type ThemeOptions = {
light: string; light: string;
}; };
export interface iSVG { export interface SVG {
id?: number; id: number;
title: string; title: string;
category: tCategory | tCategory[]; category: string | string[];
route: string | ThemeOptions; route: string | ThemeOptions;
url: string;
wordmark?: string | ThemeOptions; wordmark?: string | ThemeOptions;
brandUrl?: string; brandUrl?: string;
url: string;
} }
``` ```
- `tCategory` is a large list of categories that can be found [here](https://github.com/pheralb/svgl/blob/main/src/types/categories.ts#L1). > If you need types for the `category`, you can find them [here](https://github.com/pheralb/svgl/blob/main/src/types/categories.ts). Change the type of `category` to `Category | Category[]`.
## Endpoints ## Endpoints
### Get all SVGs
```bash ```bash
https://api.svgl.app https://api.svgl.app
``` ```
<p></p>
```json ```json
// Returns: // Returns:
[ [
@@ -77,12 +72,12 @@ https://api.svgl.app
] ]
``` ```
### Get all SVGs with limit
```bash ```bash
https://api.svgl.app?limit=10 https://api.svgl.app?limit=10
``` ```
<p></p>
```json ```json
// Returns: // Returns:
[ [
@@ -97,12 +92,12 @@ https://api.svgl.app?limit=10
] ]
``` ```
### Get SVGs by category
```bash ```bash
https://api.svgl.app/category/software https://api.svgl.app/category/software
``` ```
<p></p>
```json ```json
// Returns: // Returns:
[ [
@@ -117,16 +112,24 @@ https://api.svgl.app/category/software
] ]
``` ```
The list of categories is available [here](https://github.com/pheralb/svgl/blob/main/src/types/categories.ts) (except for the _all_ category). > The list of categories is available [here](https://github.com/pheralb/svgl/blob/main/src/types/categories.ts).
### Get the SVG code
Optimized SVG using [svgo](https://github.com/svg/svgo):
```bash ```bash
https://api.svgl.app/svg/adobe.svg https://api.svgl.app/svg/adobe.svg
``` ```
<p></p> No optimized SVG:
```bash
https://api.svgl.app/svg/adobe.svg?no-optimize
```
```html ```html
// Returns: <!-- Returns: -->
<svg <svg
width="91" width="91"
height="80" height="80"
@@ -150,33 +153,12 @@ https://api.svgl.app/svg/adobe.svg
</svg> </svg>
``` ```
```bash ### Search SVG by title
https://api.svgl.app/categories
```
<p></p>
```json
// Returns:
[
{
"category": "Software",
"total": 97
},
{
"category": "Library",
"total": 25
},
...
]
```
```bash ```bash
https://api.svgl.app?search=axiom https://api.svgl.app?search=axiom
``` ```
<p></p>
```json ```json
// Returns: // Returns:
[ [
@@ -192,3 +174,24 @@ https://api.svgl.app?search=axiom
} }
] ]
``` ```
### Get the list of categories
```bash
https://api.svgl.app/categories
```
```json
// Returns:
[
{
"category": "Software",
"total": 97
},
{
"category": "Library",
"total": 25
}
//...
]
```