0

I want to get some filtered entities by GET endpoint. This should be done by one not hardcoded parameter (e.g id, name, description, ...). I thought about smoething like that I have two params: searchKey and searchValue.

http://localhost:8080/api/cars?searchKey=name&searchValue=peugeot

But it doesn't look good. What are better scenarios for this problem?

Aro400
  • 1
  • 1
  • What is wrong with searchKey and searchValue? – Vasif Oct 29 '18 at 22:05
  • I thought there are better ways to achieve this goal than that. It looks like easiest solution but not best one . – Aro400 Oct 29 '18 at 22:12
  • Since you mention Spring I assume you use Springfox. OpenAPI 3.0 Specification actually supports [free-form query parameters](https://stackoverflow.com/q/49582559/113116), but Springfox [does not support OpenAPI 3.0](https://github.com/springfox/springfox/issues/2022) yet. – Helen Oct 29 '18 at 23:13
  • Related: [RESTful URL design for search](https://stackoverflow.com/q/207477/113116) and [How to design RESTful search/filtering?](https://stackoverflow.com/q/5020704/113116) – Helen Oct 29 '18 at 23:18

1 Answers1

0

I would personally like to create a new route http://localhost:8080/api/cars/search and provide the POST-verb to this route. This is kind of a resource creation... a new search-resource. So all in all the URL is readable and understandable + the search params are in the POST-body.

You can create a great discussion about RESTful or not... but I think it is important what you and especially your API consumers like to use!

Lennart Blom
  • 513
  • 3
  • 19