add GET method for shortening
This commit is contained in:
+4
-2
@@ -6,7 +6,7 @@ Usage: python urlshort.py <config.json>
|
||||
API (all routes are prefixed with base_path, e.g. /s):
|
||||
GET / Frontend (or health check if no static/)
|
||||
GET /api/health Health check
|
||||
POST /api/shorten Create a short URL (no API key required)
|
||||
POST/GET /api/shorten Create a short URL (no API key required)
|
||||
GET /api/urls List all short URLs (API key required)
|
||||
GET /api/urls/<code> Get info for a code (no API key required)
|
||||
GET /api/lookup?url=<url> Look up by original URL (no API key required)
|
||||
@@ -357,6 +357,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif path == "/api/health":
|
||||
self._send_json(200, {"status": "ok", "service": "url-shortener"})
|
||||
|
||||
elif path == "/api/shorten":
|
||||
self._handle_shorten()
|
||||
|
||||
elif path == "/api/urls":
|
||||
self._handle_list_urls()
|
||||
|
||||
@@ -433,7 +436,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._error(400, "Invalid JSON body")
|
||||
return
|
||||
|
||||
|
||||
# url: query param takes precedence, then body
|
||||
original_url = qs.get("url", [""])[0] or str(body.get("url", "")).strip()
|
||||
if not original_url:
|
||||
|
||||
Reference in New Issue
Block a user