What is the RESTful way to query with a boolean operation?

This is a side question for a query with filters

Say that my application manages objects called workload, with the following fields. I want to open a REST interface for a user to request workloads using labels.

"Workload": {"id":"test1", "labels":["A", "B", "C"]}
"Workload": {"id":"test2", "labels":["A", "C", "D"]}
"Workload": {"id":"test3", "labels":["A", "B", "D"]}

Question . How do I create a REST endpoint to support the request workload using basic logical operations?

Request example 2 . I want to get all workloads labeled "A" or "B", but not "C"

There is no clue how to make such a rest api at all, except that the user requests requests for A, B, C separately, and then they perform their own installation operations themselves? (What a great user experience ...)

A similar question here concerns a query with logical logic on different filters, but it does not seem to be applicable for repeated filtering. (In this case, the labels. It seems strange to do GET /workloads/labels:A/labels:B)

+4
source share
1 answer

Depending on the exact requirements, I might start with the google approach. Just submit a request form and create a primitive query language that can be just textual (no need to use json if it's simple enough).

Thus, the search page will look something like this:

{ "searchForm": {
    "target": "/workloads",
    "method": "GET",
    "components": [{ "name": "q" }]
  }
}

media-type for the search page will determine how to use the form, perhaps it should make a request, for example:

GET /workloads?q=+A+B-C

. , "+" "-", Google. , , , , / .

, RESTful, -uri , -.

0

Source: https://habr.com/ru/post/1655668/


All Articles