Page MenuHomeSoftware Heritage

Add support for content negotiation in swh's API

Authored by douardda on Jan 24 2019, 9:29 AM.



Using these 2 negotiate formatters, it is possible to write Flask endpoints

from flask import Flask
from negotiate.flask import negotiate
from swh.core.api import JSONFormatter, MshpackFormatter

app = Flask()

def somewhere():
    return {'some': 'content'}


Diff Detail

rDCORE Foundations and core functionalities
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

douardda created this revision.Jan 24 2019, 9:29 AM

The idea behind this diff is to be able to use/play with internal APIs (scheduler, incexers, etc.) using cli tools (curl, httpie etc.)
In which case, the msgpack format is a pain in the neck. With this, the APIs can default to use json as response's content type, but honor the Accept header so the remote servers used in the code can still use msgpack as serialization format.

ardumont added inline comments.

That won't be enough for all of our internal apis (but i have the feeling you know that and want to go incrementally ;)
I think of the storage for example but there might be others as well (indexer?).

ardumont added inline comments.Jan 24 2019, 10:16 AM

why did you add that part?
That confuses me, i'm checking ;)

douardda marked 2 inline comments as done.Jan 24 2019, 10:29 AM
douardda added inline comments.

Yes,so far this is enough for the scheduler (diff not yet submitted), but indeed it will need more tweaking...


In the context of an API client (remote service), we want to make sure we ask the API server for msgpack encoded response. The content-type only declare we send msgpack encoded payload, not what we ask for in return.

ardumont accepted this revision.Jan 24 2019, 10:32 AM
ardumont added inline comments.

yes, remote! I misread. I keep forgetting that this code is the client part ;)

In the end, this was missing instruction all along (independent from the negotiate library introduction here).


This revision is now accepted and ready to land.Jan 24 2019, 10:32 AM
This revision was automatically updated to reflect the committed changes.