For a REST interface:
What is the best way to allow the client to set many equally named parameters in a GET?
For example if the client should specify multiple possible colors
www.example.com/products/{color=green|color=yellow|color=white| ...}
The HTTP protocol does not limit the size of GET requests, but each browser and server have a data transfer limit. It is recommended to use an average of 512-1024 Kb or a maximum of 5 parameters to create one request.
To send query parameters in a GET request in JavaScript, we can pass a list of search query parameters using the URLSearchParams API.
A URL can have several path parameters, each denoted with curly braces { } . Each path parameter must be substituted with an actual value when the client makes an API call. In OpenAPI, a path parameter is defined using in: path . The parameter name must be the same as specified in the path.
Something like this would be fine:
GET http://www.example.com/products?colors=green,yellow,white
Despite popular opinion, there is no REST constraint that says you should not use query string parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With