Hello everyone,
I’m using JSONAPI to implement Service-to-Service communication and Application-to-Service communication. I’d like to know if the following Content Negotiation strategy is aligned with JSONAPI 1.0.
Can I use the Accept
header to the tell server which API I’d like clients to use?
Clients MUST send all JSON API data in request documents with the header
Content-Type: application/vnd.api+json
without any media type parameters.
Clients that include the JSON API media type in their Accept header MUST specify the media type there at least once without any media type parameters.
In the dependency diagram below, you can see that my Collector Service publishes two different APIs for two different supporting actors.
application/vnd.harvester-api-1.0+json
+-------------+ +-------------+
| | | |
| Collector | | Harvester |
| Service <----------------+ Service |
| | | |
+------+------+ +-------------+
^
|
| application/vnd.dashboard-api-1.0+json
|
|
+------+------+
| |
| Dashboard |
| Application |
| |
+-------------+
When the Harvester Service pushes data to the Collector it’d use:
POST /events
Content-Type: application/vnd.api+json
Accept: application/vnd.harvester-1.0-+json
When it’s the Dashboard Application the one pulling data, it’d use:
GET /events
Content-Type: application/vnd.api+json
Accept: application/vnd.dashboard-api-1.0-+json
I could express the same separation of concerns using namespaces in the URL, it’s my personal preference to keep URLs “clean”.
POST /harvester/1/events
GET /dashboard/1/events
I was wondering if the Content-Type
vs Accept
header would be considered still valid.