Accepts and Content-Type

90 views
Skip to first unread message

Michael Tiller

unread,
Jan 30, 2017, 3:26:49 PM1/30/17
to Siren Hypermedia
If I have a client that sends "application/json" in the Accepts header and I serve them back Siren, should I set the "Content-Type" header to "application/json" or "application/vnd.siren+json"?

I'm thinking "application/vnd.siren+json" because Content-Type is meant to indicate what format the response in. Since it is Siren, I should say that.  But I'm concerned that there is some part of content negotiation I'm missing.  I researched this and I didn't see anything, but I could easily imagine there is some guidance somewhere that says I should return one of the formats explicitly listed in the Accepts choices, if possible.  I'm concerned about cases where a client might say "I want application/json" and if I send them back some "application/vnd.siren+json" they'll think that this some unknown format and reject the response.

Further complicating the discussion is the fact that something can be BOTH JSON and Siren, but there is no way to express this in the response (short of multiple Content-Type headers, but that seems like a very bad idea).

Comments?

Thanks.

--
Mike

Kevin Swiber

unread,
Jan 31, 2017, 11:53:20 PM1/31/17
to Siren Hypermedia
Hey Mike,

If the negotiated MIME type is application/json, that's what I would send back as the Content-Type.  It's very possible that the client understands JSON but not the semantics that come along with Siren.  The Chrome browser is a perfect example of this.  It renders application/json (albeit in an ugly fashion without a good Chrome extension), and it downloads application/vnd.siren+json as a file.

This is what I do with Siren APIs.  I support both application/json and application/vnd.siren+json, and I return whatever gets negotiated based on the Accept header.

Cheers,

Kevin

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermed...@googlegroups.com.
To post to this group, send email to siren-hy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/siren-hypermedia/d2b15556-95c8-425b-9705-ba11366a3390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Tiller

unread,
Feb 1, 2017, 7:34:57 AM2/1/17
to siren-hy...@googlegroups.com
Kevin,

  Thanks for the response.  Great point about Chrome.  Reminds me that I need to pay more attention to the q parameters in the Accept header as well.

  I'm curious, if the client asks for application/json, do you return a Siren instance (it is JSON after all) or do you return some subset of information, e.g., just properties?

--
Mike


On Tue, Jan 31, 2017 at 11:53 PM, Kevin Swiber <ksw...@gmail.com> wrote:
Hey Mike,

If the negotiated MIME type is application/json, that's what I would send back as the Content-Type.  It's very possible that the client understands JSON but not the semantics that come along with Siren.  The Chrome browser is a perfect example of this.  It renders application/json (albeit in an ugly fashion without a good Chrome extension), and it downloads application/vnd.siren+json as a file.

This is what I do with Siren APIs.  I support both application/json and application/vnd.siren+json, and I return whatever gets negotiated based on the Accept header.

Cheers,

Kevin
On Mon, Jan 30, 2017 at 12:26 PM Michael Tiller <michael...@gmail.com> wrote:
If I have a client that sends "application/json" in the Accepts header and I serve them back Siren, should I set the "Content-Type" header to "application/json" or "application/vnd.siren+json"?

I'm thinking "application/vnd.siren+json" because Content-Type is meant to indicate what format the response in. Since it is Siren, I should say that.  But I'm concerned that there is some part of content negotiation I'm missing.  I researched this and I didn't see anything, but I could easily imagine there is some guidance somewhere that says I should return one of the formats explicitly listed in the Accepts choices, if possible.  I'm concerned about cases where a client might say "I want application/json" and if I send them back some "application/vnd.siren+json" they'll think that this some unknown format and reject the response.

Further complicating the discussion is the fact that something can be BOTH JSON and Siren, but there is no way to express this in the response (short of multiple Content-Type headers, but that seems like a very bad idea).

Comments?

Thanks.

--
Mike

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermedia+unsubscribe@googlegroups.com.
To post to this group, send email to siren-hypermedia@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermedia+unsubscribe@googlegroups.com.
To post to this group, send email to siren-hypermedia@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/siren-hypermedia/CAGA7vN5R9ZW_wn-EcsVjeqr4YYuH%2B8g8h9fs1NST1dC772q-ZQ%40mail.gmail.com.

Alex Soto

unread,
Feb 1, 2017, 11:11:43 AM2/1/17
to siren-hy...@googlegroups.com
I return the same response since siren is just json.

Kevin Swiber

unread,
Feb 1, 2017, 1:22:53 PM2/1/17
to siren-hy...@googlegroups.com
I return the Siren representation whether the client asks for application/json or application/vnd.siren+json.

On Wed, Feb 1, 2017 at 4:34 AM Michael Tiller <michael...@gmail.com> wrote:
Kevin,

  Thanks for the response.  Great point about Chrome.  Reminds me that I need to pay more attention to the q parameters in the Accept header as well.

  I'm curious, if the client asks for application/json, do you return a Siren instance (it is JSON after all) or do you return some subset of information, e.g., just properties?

--
Mike


On Tue, Jan 31, 2017 at 11:53 PM, Kevin Swiber <ksw...@gmail.com> wrote:
Hey Mike,

If the negotiated MIME type is application/json, that's what I would send back as the Content-Type.  It's very possible that the client understands JSON but not the semantics that come along with Siren.  The Chrome browser is a perfect example of this.  It renders application/json (albeit in an ugly fashion without a good Chrome extension), and it downloads application/vnd.siren+json as a file.

This is what I do with Siren APIs.  I support both application/json and application/vnd.siren+json, and I return whatever gets negotiated based on the Accept header.

Cheers,

Kevin
On Mon, Jan 30, 2017 at 12:26 PM Michael Tiller <michael...@gmail.com> wrote:
If I have a client that sends "application/json" in the Accepts header and I serve them back Siren, should I set the "Content-Type" header to "application/json" or "application/vnd.siren+json"?

I'm thinking "application/vnd.siren+json" because Content-Type is meant to indicate what format the response in. Since it is Siren, I should say that.  But I'm concerned that there is some part of content negotiation I'm missing.  I researched this and I didn't see anything, but I could easily imagine there is some guidance somewhere that says I should return one of the formats explicitly listed in the Accepts choices, if possible.  I'm concerned about cases where a client might say "I want application/json" and if I send them back some "application/vnd.siren+json" they'll think that this some unknown format and reject the response.

Further complicating the discussion is the fact that something can be BOTH JSON and Siren, but there is no way to express this in the response (short of multiple Content-Type headers, but that seems like a very bad idea).

Comments?

Thanks.

--
Mike

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermed...@googlegroups.com.
To post to this group, send email to siren-hy...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermed...@googlegroups.com.
To post to this group, send email to siren-hy...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermed...@googlegroups.com.
To post to this group, send email to siren-hy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/siren-hypermedia/CANmMiBbSkEczPM90MYABOmpWDro7332JjScZO9_UhNrN3qCSDw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages