elixir-cloud-aai / trs-filer

Lightweight, flexible Flask/Gunicorn-based GA4GH TRS implementation
Apache License 2.0
8 stars 6 forks source link

Implement "text/plain" content type for endpoints supporting it #74

Open uniqueg opened 4 years ago

uniqueg commented 4 years ago

Description

Several endpoints in the TRS specification allow requesting a text/plain response rather than the default application/json response. This is currently not implemented for any of the endpoints.

Proposed solution

To implement this, first a generic function investigating the header should be implemented that accepts a list of defined content types for that particular endpoint as well as either all headers or just the Accept header (if available) associated with the request. The function should then inspect the value of the Accept header and compare it to the list of supported content types. If the requested content type is not in the list of supported content types, a BadRequest should be returned. If the header is absent, the default (application/json) should be returned/set. Otherwise, i.e., if the content type specified in the Accept header is among the list of supported types, it should be returned. This function can be used for all endpoints. Then, depending on which validated content type was requested, the Content-Type header of the response should be set accordingly (e.g., if text/plain was requested, the Content-Type header of the response should be set to text/plain).

Possible caveats