URL 缩短服务的系统设计
FreeGuideOnline
最新
2026-07-10
POST /api/v1/shorten Content-Type: application/json
{ "long_url": "https://www.example.com/some/very/long/url?param=value", "expires_in_days": 365, // 可选 "custom_alias": "myalias" // 可选 }
响应:
```json
{
"short_url": "https://short.link/abc123",
"short_code": "abc123",
"long_url": "...",
"created_at": "...",
"expires_at": "..."
}
错误处理:若自定义别名已被占用,返回 409 Conflict。
7.2 重定向
GET /{short_code}
返回 302,头部 Location 指向原 URL。
若短码不存在或已过期,返回 404。
7.3 统计分析(可选)
GET /api/v1/stats/{short_code}