Go Short API Docs
用于创建和访问短链接的轻量级接口说明。
创建短链接
POST /shorten
如果服务配置了 API_SECRET,请求需要包含 X-API-Secret 请求头。
curl -X POST https://s.21rv.com/shorten \
-H "Content-Type: application/json" \
-H "X-API-Secret: your-secret" \
-d '{"url": "https://www.example.com"}'
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 需要缩短的原始 URL。 |
响应示例:
{
"code": "abc1",
"short_url": "https://s.21rv.com/abc1",
"url": "https://www.example.com",
"visit_count": 0
}
访问短链接
GET /:code
curl -L https://s.21rv.com/abc1
健康检查
GET /health
curl https://s.21rv.com/health
错误响应
| 状态码 | 说明 |
|---|---|
| 400 | 请求体格式错误或缺少 url。 |
| 401 | API_SECRET 已配置,但请求没有提供正确的 API Secret。 |
| 404 | 短链接不存在。 |
| 500 | 生成短链接或数据库操作失败。 |