remove API key requirement from POST /api/shorten
This commit is contained in:
@@ -124,15 +124,14 @@ Health check endpoint.
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/shorten` 🔒
|
||||
Create a new short URL.
|
||||
### `POST /api/shorten`
|
||||
Create a new short URL. No API key required.
|
||||
|
||||
Fields can be passed as **query parameters** (URL-encoded) or in a **JSON request body**.
|
||||
Query parameters take precedence over body fields.
|
||||
|
||||
| Field | Required | Description |
|
||||
|------------------|----------|-----------------------------------------------------------|
|
||||
| `api_key` | ✅ | API key for authentication |
|
||||
| `url` | ✅ | The URL to shorten (must start with `http://` or `https://`) |
|
||||
| `retention_days` | | Override the default retention period for this URL |
|
||||
|
||||
@@ -221,10 +220,10 @@ Increments `visit_count` on each hit.
|
||||
# Shorten a URL (JSON body)
|
||||
curl -X POST http://localhost:8080/s/api/shorten \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"api_key": "change-this-secret-key", "url": "https://github.com"}'
|
||||
-d '{"url": "https://github.com"}'
|
||||
|
||||
# Shorten a URL (query parameters)
|
||||
curl -X POST "http://localhost:8080/s/api/shorten?api_key=change-this-secret-key&url=https%3A%2F%2Fgithub.com&retention_days=30"
|
||||
curl -X POST "http://localhost:8080/s/api/shorten?url=https%3A%2F%2Fgithub.com&retention_days=30"
|
||||
|
||||
# Follow the redirect
|
||||
curl -L http://localhost:8080/s/aB3xYz
|
||||
@@ -248,7 +247,7 @@ curl "http://localhost:8080/s/api/lookup?url=https%3A%2F%2Fexample.com"
|
||||
|
||||
A clean single-page frontend is included in `static/`. It provides:
|
||||
|
||||
- **URL shortening** — paste a URL and press Enter to create a short URL (requires API key)
|
||||
- **URL shortening** — paste a URL and press Enter to create a short URL
|
||||
- **Existing URL lookup** — as you type a URL, the frontend checks if it already exists and shows its metadata
|
||||
- **Admin table** — enter a valid API key to see all shortened URLs in a sortable, paginated table
|
||||
- **Copy & Delete** — per-row copy and delete buttons (delete on hover only)
|
||||
|
||||
Reference in New Issue
Block a user