mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🛠️ Refactor API documentation for clarity and consistency; update URLs and TypeScript types
This commit is contained in:
+54
-51
@@ -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.
|
||||
|
||||
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
|
||||
https://api.svgl.app
|
||||
# or
|
||||
```
|
||||
|
||||
Categories URL:
|
||||
|
||||
```bash
|
||||
https://api.svgl.app/categories
|
||||
```
|
||||
|
||||
## Typescript usage
|
||||
## Typescript
|
||||
|
||||
- For categories:
|
||||
|
||||
```ts
|
||||
export interface Category {
|
||||
category: string;
|
||||
total: number;
|
||||
}
|
||||
```
|
||||
|
||||
- For SVGs:
|
||||
You can use the following types for the SVG responses:
|
||||
|
||||
```ts
|
||||
export type ThemeOptions = {
|
||||
@@ -42,27 +37,27 @@ export type ThemeOptions = {
|
||||
light: string;
|
||||
};
|
||||
|
||||
export interface iSVG {
|
||||
id?: number;
|
||||
export interface SVG {
|
||||
id: number;
|
||||
title: string;
|
||||
category: tCategory | tCategory[];
|
||||
category: string | string[];
|
||||
route: string | ThemeOptions;
|
||||
url: string;
|
||||
wordmark?: string | ThemeOptions;
|
||||
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
|
||||
|
||||
### Get all SVGs
|
||||
|
||||
```bash
|
||||
https://api.svgl.app
|
||||
```
|
||||
|
||||
<p></p>
|
||||
|
||||
```json
|
||||
// Returns:
|
||||
[
|
||||
@@ -77,12 +72,12 @@ https://api.svgl.app
|
||||
]
|
||||
```
|
||||
|
||||
### Get all SVGs with limit
|
||||
|
||||
```bash
|
||||
https://api.svgl.app?limit=10
|
||||
```
|
||||
|
||||
<p></p>
|
||||
|
||||
```json
|
||||
// Returns:
|
||||
[
|
||||
@@ -97,12 +92,12 @@ https://api.svgl.app?limit=10
|
||||
]
|
||||
```
|
||||
|
||||
### Get SVGs by category
|
||||
|
||||
```bash
|
||||
https://api.svgl.app/category/software
|
||||
```
|
||||
|
||||
<p></p>
|
||||
|
||||
```json
|
||||
// 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
|
||||
https://api.svgl.app/svg/adobe.svg
|
||||
```
|
||||
|
||||
<p></p>
|
||||
No optimized SVG:
|
||||
|
||||
```bash
|
||||
https://api.svgl.app/svg/adobe.svg?no-optimize
|
||||
```
|
||||
|
||||
```html
|
||||
// Returns:
|
||||
<!-- Returns: -->
|
||||
<svg
|
||||
width="91"
|
||||
height="80"
|
||||
@@ -150,33 +153,12 @@ https://api.svgl.app/svg/adobe.svg
|
||||
</svg>
|
||||
```
|
||||
|
||||
```bash
|
||||
https://api.svgl.app/categories
|
||||
```
|
||||
|
||||
<p></p>
|
||||
|
||||
```json
|
||||
// Returns:
|
||||
[
|
||||
{
|
||||
"category": "Software",
|
||||
"total": 97
|
||||
},
|
||||
{
|
||||
"category": "Library",
|
||||
"total": 25
|
||||
},
|
||||
...
|
||||
]
|
||||
```
|
||||
### Search SVG by title
|
||||
|
||||
```bash
|
||||
https://api.svgl.app?search=axiom
|
||||
```
|
||||
|
||||
<p></p>
|
||||
|
||||
```json
|
||||
// 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
|
||||
}
|
||||
//...
|
||||
]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user