D
D
Dmitry2018-10-13 14:22:55
MySQL
Dmitry, 2018-10-13 14:22:55

How to correctly implement RestAPI filtering in a Spring Boot application?

Good afternoon.
I am making a small rest api application.
There is a module that communicates with the database (common), there is another module that also uses common, and now the turn has come to the rest api of the module, which will also use the common module. Common is written without using hibernate, used with c3p0 and mysql connector.
The question is how to properly filter elements when resting a request? For example, there is
GET /video/?releaseFrom=02102013&releaseTo=02102014&imdbRate=gt(7.5)
respectively, the filter parameters are optional, if you run without parameters at all, the last 20 records will be returned, for example. The set of parameters may be different, for example, title may be passed or something else.
The question of how to properly filter, write different sql queries for all possible options is very doubtful.
Is it right to create a separate procedure on the database itself and already in it collect the necessary query using concatenation. Or collect the request in java in the same way, depending on the availability of parameters. The murky work is not entirely clear with prepared query parameters in this case.
How is it done in real projects?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-10-13
@Sad_Bro

In short, the task is not simple, I found many examples using ORM. In my case, I will have to collect my own apparently.
REST Query Language
https://www.baeldung.com/spring-rest-api-query-sea...

K
kidar2, 2018-10-14
@kidar2

Judging by the task, you are not afraid of all sorts of sql injects, can then pass the condition for where directly in the url? Straight sql piece.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question