Skip to content

Issue 538.7: Plain Text Content Negotiation for Audit API #568

@ngjunsiang

Description

@ngjunsiang

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

  • All API key endpoints support text/plain Accept header
  • Plain text responses are properly formatted
  • Content negotiation defaults to JSON for /
  • Tests for both JSON and plain text responses
  • Documentation of plain text formats

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Planning

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions