接口地址: https://l-i.biz/shorten
请求方法: POST
代码示例
API 文档
以下内容由 deepseek 生成
URL Shortener API Documentation
Overview
This API provides functionality to shorten long URLs and redirect short URLs to their original long URLs. It is built using Express.js and Prisma with a PostgreSQL database. The API uses the nanoid library to generate unique short IDs for the shortened URLs.
Base URL
https://l-i.biz/
Endpoints
- Shorten a URL
Endpoint: POST /shorten
Description: Shortens a given long URL and returns the shortened URL.
Request Body:
url (string, required): The long URL to be shortened. Must include http:// or https://.
Response:
200 OK: Returns the shortened URL.
{
"url": "https://l-i.biz/abc123"
}
400 Bad Request: If the URL is missing or invalid.
{
"error": "Please provide a URL"
}
{
"error": "Please provide a valid URL (including http:// or https://)"
}
500 Internal Server Error: If an error occurs while processing the URL.
{
"error": "An error occurred while processing the URL"
}
- Redirect to Original URL
Endpoint: GET /:id
Description: Redirects a short URL to its original long URL.
Path Parameter:
id (string, required): The short ID of the URL.
Response:
302 Found: Redirects to the original long URL.
404 Not Found: If the short ID does not exist.
{
"error": "404 NOT FOUND"
}
500 Internal Server Error: If an error occurs while fetching the URL record.
{
"error": "500 INTERNAL SERVER ERROR"
}
- Health Check
Endpoint: GET /
Description: Returns a status message indicating the service is running.
Response:
418 I’m a teapot: Indicates the service is running.
{
"message": "I'm a teapot"
}
Error Handling
The API returns appropriate HTTP status codes and error messages in JSON format for errors. Common error codes include:
400 Bad Request: Invalid request parameters or body.
404 Not Found: Resource not found.
500 Internal Server Error: Server-side error.
Example Usage
Shorten a URL
Request:
POST /shorten
Content-Type: application/json
{
"url": "https://www.example.com"
}
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"url": "https://l-i.biz/abc123"
}
Redirect to Original URL
Request:
GET /abc123
Response:
HTTP/1.1 302 Found
Location: https://www.example.com
Health Check
Request:
GET /
Response:
HTTP/1.1 418 I’m a teapot
Content-Type: application/json
{
"message": "I'm a teapot"
}