How to return an alternate representation of an image in a REST API? -
consider contrived scenario. have resource, foo
. when user requests representation of foo
resource, return json representation of said resource:
get: /foo/1 accept: application/json response: { 'id' : 'foo1', 'datecreated' : '11-12-2014', ... other metadata ... }
additionally, can request foo
resource accept
type of image/png
image representation of said resource:
get: /foo/1 accept: image/png response: image data
what's going on here server side image library reading necessary data construct image , returning response.
here question comes in ... i'm needing return data used construct image on server side client. example, let's consider d3.js exists on server side, , i'm building json being fed d3:
d3.json('/path/to/my/json', function() { ... });
and renders static image (e.g., pie chart) , returned. return data used construct image d3, if clients want plug json own instance of d3 on client side, can so.
for example, let's consider following json used create pie chart representing foo
:
[ { "label": "one", "value" : 29.765957771107 } , { "label": "two", "value" : 0 } , { "label": "three", "value" : 32.807804682612 } , { "label": "four", "value" : 196.45946739256 } , { "label": "five", "value" : 0.19434030906893 } ]
this json fed image library on server generate static image returned in case of accept: image/png
. i'm attempting return json client in addition json represents metadata of foo
.
however, conflicts, because return type if also json. so, it's not possible have accept header of application/json
here because of we've said above.
is fair alternate representation of foo/1
resource? should request custom image type (e.g., accept: image/x-foo+json
) or custom application type (e.g., application/x-foo+json
)? or, going wrong?
Comments
Post a Comment