C
C#8mo ago
Core

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
Jimmacle
Jimmacle8mo ago
i would do that if i wanted to support the client choosing exactly which fields they want returned
Core
Core8mo ago
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?
Jimmacle
Jimmacle8mo ago
right, query parameters are generally for options provided by the client
Core
Core8mo ago
Thank you!
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View