Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): decouple request and response encoding in resource manager #2520

Merged

Conversation

schoren
Copy link
Collaborator

@schoren schoren commented May 10, 2023

This PR splits the request and response encoding in resource manager. This allows for clients to do requests in one format but expect the response to be in another.

This is useful for example in the CLI, where the client issues a request with a body in YAML format, from the contents of a user created yaml definition file), but then it needs to parse the response to beautify it. Also the user can request the output to be in json.

Instead of having the client manipulate responses, it can just configure the requests with standard http headers.
This reduction in manipulation along the pipeline reduces the need for client code, and reduces the chances of inconsistencies in formats.

Example

Request:

POST /api/exampleresources
Content-Type: text/yaml
Accept: application/json

type: ExampleResource
spec:
  name: the name
  other_value: etc....

Response:

Content-Type: application/json

{
  "type": "ExampleResource",
  "spec": {
    "id": "123",
    "name": "the name",
    "other_value": "etc..."
  }
}

Notes

  1. If no relevant header is present, the API fallbacks to JSON, as it always did,
  2. Clients that don't need this feature can continue to use just the Content-Type header and the response will fallback to the same content type as the request,
  3. Any of Content-Type or Accept header can be used alone, resulting in the previously described behaviour.

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

@schoren schoren merged commit 4a8ae72 into main May 11, 2023
31 checks passed
@schoren schoren deleted the feat/resourcemanager-decuple-request-from-response-encoding branch May 11, 2023 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants