Design REST API to request certain fields
Hello, this is a generic question
If a model has six fields, but as a response you only want to include four, a DTO would be used. This means that the
GET /users
request would contain a list of users, each with four fields.
Instead of GET /users
, should the request URL be GET /users?fields=name,username,etc
in this scenario?
I am wondering if this is used in real-life scenarios when the consumer of the API is a SPA.5 Replies
i would do that if i wanted to support the client choosing exactly which fields they want returned
I am displaying the data in a table, which means the user cannot individually choose the rendered fields. So this type of request design should only be used when the user has choice over the displayed data?
right, query parameters are generally for options provided by the client
Thank you!
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View