How to design a REST API to request only specific fields from a resource

I’d go for option 2.

If the consumer just requests the resource URL (/posts/42) they receive the default fields.

Then consumers can alter the default response by defining values in the query string like:

/posts/42/fields?subject,author_name

This has worked well for me in the past and is how some other well know APIs work, e.g. Facebook

Although I’d change the request to be:

/posts/42?fields=subject,author_name

/post/42 is the resource, not fields.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)