REST: Is it considered restful if API sends back two type of response? -
we have stock website , buyers connect sellers. creating api let buyers push contact details , seller details. transaction , logged in our database. have created following api:
the request post, url looks like:
/api/leads
the request body looks like:
{ "buyermobile": "9999999999", "stockid": "123" }
the response looks like:
{ "sellermobile" : "8888888888", "selleraddress": "123 avenue park" }
we have new requirement, i.e. need send pdf url (instead of "sellermobile" & "selleraddress"). pdf url contain seller details in case comes 1 of our client.
we have modified same api, request body looks like:
{ "buyermobile": "9999999999", "stockid": "123", "ispdf": true }
the response looks like:
{ "sellerdetailspdf" : "https://example.com/sellerdetails-1.pdf", }
is restful this? or should create separate api getting response pdf?
i wouldn't approach way. happens when need add xls? add "isxls" request too?
things i'd consider:
use mime type content negotiation. post same request, , specify in accept
header expect - json, pdf, etc. you're getting report instead of link report, may or may not better.
- or -
include link in typical lead response.
{ "sellermobile" : "8888888888", "selleraddress": "123 avenue park", "_links": { "seller-details-pdf": "https://example.com/sellerdetails-1.pdf" } }
- or -
support query parameter specifies type in response.
- or -
have single property specifies type in response, rather boolean. cleaner extend when add new response types.
the first 2 options have bonus don't require clients handle multiple response types single request. that's not forbidden spec, it's annoying clients. try not annoy people want pay you. :)
Comments
Post a Comment