C
C#12mo 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
Jimmacle12mo ago
i would do that if i wanted to support the client choosing exactly which fields they want returned
Core
CoreOP12mo 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
Jimmacle12mo ago
right, query parameters are generally for options provided by the client
Core
CoreOP12mo ago
Thank you!
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server