Summary
Add plain text content negotiation support for campus.audit API endpoints.
Background
Parent issue: #538
The original API key requirements (#541) mentioned supporting both JSON and plain text content types, but only JSON is currently implemented.
Requirements
1. Support text/plain Content-Type
For endpoints that return single resources or simple messages, support plain text responses:
Create endpoint (POST /audit/v1/apikeys):
- Accept:
application/json → Return JSON with key details
- Accept:
text/plain → Return plaintext key value only
List endpoint (GET /audit/v1/apikeys):
- Accept:
application/json → Return JSON array
- Accept:
text/plain → Return formatted text list (one per line)
Get endpoint (GET /audit/v1/apikeys/<id>):
- Accept:
application/json → Return JSON object
- Accept:
text/plain → Return formatted key details
2. Content Negotiation
Use Flask's request.accept_mimetypes to determine response format:
from flask import request
if request.accept_mimetypes.accept_json:
return json_response, 200
elif 'text/plain' in request.accept_mimetypes:
return plain_text_response, 200, {'Content-Type': 'text/plain'}
else:
return json_response, 200 # Default to JSON
3. Plain Text Formats
Define simple, human-readable formats:
- Create: Just the key value on its own line
- List: One key per line with format:
name:owner_id:scopes
- Get: Multi-line format with key details
- Delete: Simple "OK" or "Revoked" message
Acceptance Criteria
Related
Summary
Add plain text content negotiation support for campus.audit API endpoints.
Background
Parent issue: #538
The original API key requirements (#541) mentioned supporting both JSON and plain text content types, but only JSON is currently implemented.
Requirements
1. Support text/plain Content-Type
For endpoints that return single resources or simple messages, support plain text responses:
Create endpoint (
POST /audit/v1/apikeys):application/json→ Return JSON with key detailstext/plain→ Return plaintext key value onlyList endpoint (
GET /audit/v1/apikeys):application/json→ Return JSON arraytext/plain→ Return formatted text list (one per line)Get endpoint (
GET /audit/v1/apikeys/<id>):application/json→ Return JSON objecttext/plain→ Return formatted key details2. Content Negotiation
Use Flask's
request.accept_mimetypesto determine response format:3. Plain Text Formats
Define simple, human-readable formats:
name:owner_id:scopesAcceptance Criteria
Related