Valuable? Fields support in REST API

98 Views Asked by At

I've read some topics about GraphQL, and one of the great features I like is you can specify fields you want (Client End). I'm thinking maybe I can also add it into REST API. I look around and find there has already such specification: fetching-sparse-fieldsets

So I'm trying to add such feature in Symfony. (Especially, in FOSRestBundle+JSMSerializer). But I'm not quite sure whether it is valuable or not. Can someone give you advice?

1

There are 1 best solutions below

2
On

That is a question you should ask to your API users and your customer. It might be useful for the API user, but it has a lot of downsides:

  • By building it yourself, you spend a lot of time by developing, testing and maintaining this 'optional' feature. Is the customer willing to pay? (YAGNI)
  • As mentioned above, you must maintain the code for this feature, you cannot remove it unless you decide to release a new API version. As external packages change, your code might require an update aswell.
  • It can become difficult when troubleshooting. API users might be trying to retrieve a field that isn't specified in the API URL (ofcourse these issues arise after project transfers to other developers). Questions can come up why some data isn't available, but is present in API documentation.

Especially the first one in the list is incredibly important. Don't build features that the customer does not need. Personally I always return all accessible data available, even null values. The API users decide what to do with that data. Bandwidth isn't such a problem these days I guess.