Errors
This section details possible errors the Py URL Shortener API can return, along with the status codes and reasons.
Common Error Responses
| HTTP Status | Error Type | Description |
|---|---|---|
| 404 | Not Found | The requested URL or code does not exist. For example, accessing /r/invalidCode. |
| 410 | Gone | The requested short URL has expired. Accessing an expired URL will return this. |
| 422 | Unprocessable Entity | Invalid input data. For example, providing a malformed URL in the /shorten endpoint. |
| 500 | Internal Server Error | Unexpected server errors, such as database connection issues. |
Examples
1. Shorten URL with invalid URL
Request:
POST /api/v1/shorten
Content-Type: application/json
{
"url": "ht!tp://invalid-url",
"expires_in": 60
}
Response:
{
"detail": [
{
"loc": ["body", "url"],
"msg": "invalid or missing URL",
"type": "value_error.url"
}
]
}
2. Access expired URL
Request:
GET /r/expired123
Response:
{
"detail": "URL expired"
}
3. Access non-existent short code
Request:
GET /r/notfound
Response:
{
"detail": "URL not found"
}