json - REST - Partial Resources -
it's common in rest design allow partial resources returned. in case; want allow user specify fields of resource returned in json representation of resource.
for example lets have resource person:
{ "id": 12, "name":{ "first":"angie", "last": "smith", "middle": "joy", "maiden": "crowly", }, "address": { "street": "1122 st.", ..and on... }, ... , on }
lets list of params pretty long. , lets have api consumer @ beginning of creating api design wants couple fields id , name.first back. i'm assuming it's common allow this:
/person?fields=id,name
where fields says want fields back.
the question have is, should person resource return fields nulls , fields values or should return person representation fields id , name , literally remove other params dynamically backend.
seems #2 cleaner, make sense in rest, or people return other fields (to make sure we're keeping representation in terms of structure/schema consistent/reliable) nulls?
as suggested, option 2 cleaner , yes makes sense in rest.
adding null defeats part of purpose of partial responses makes response body larger needs be.
an example of use case described shown on google developer forum; in partial response section.
Comments
Post a Comment