I have the following problem:
āDisplay a button that changes the status of a resource, the button is only showed if there is a record in DB where we have status=VALID and OPEN=true
In order to check that the condition is met a query that searches for this two conditions must be used, and here comes my problem.
Creating an API that returns true/false based on a hardcoded query doesn't seem such a good solution, because it isn't flexible at all and doesn't fit into REST, because it doesn't represent an action on a resource.
How do I create an api that checks if a certain condition is met, while making it as flexible as possible and adhering to REST principles?
Something that comes to mind is a GET count api with URL: namespace/resources/count that supports REST query language, with which the consumer can filter out DB results and check if the condition is met, based on the returned number of results.
Does anybody have guidelines or had encountered this problem in the past? I am waiting to hear your suggestions!
Right now I am going with the highly specific api that simply returns true/false, because I am running out of time, but I might have to change my implementaion in the future.
From the API point of view, it does not matter how the relevant information (status
, etc.) is presented and in what storage (these are internal aspects of the implementation).
From a REST API design perspective, we can define the following resources in the context of our task that will return the corresponding resource attributes to us:
GET /resources/{resource_id}/status
GET /resources/{resource_id}/isOpen