Reputation: 550
I have a Workflow happening from product 1 to product 2 back to product 1 through REST apis.
We're wanting to keep our API RESTful and use best practices.
What is the best way for product 2 to give feedback to product 1.
In other words, is it unheard of for a REST API to make outbound calls or is a REST API strictly an observing service waiting on input only.
Upvotes: 0
Views: 255
Reputation: 3065
Responding to your first question "Can a REST API make requests?", I would say "no"... but the application behind the service API can definitely make requests to other REST APIs.
A REST API does not specify "requests" to other APIs... You should think of REST APIs from the perspective of each user/API client, not in terms of the "coordination view" of multiple services, that is another level view of the system. This means, users of service 1 will see REST API of that service, and internally service 1 can call service 2 or other services, and vice versa, but it should not be perceived by service 1 users (API clients). So, I would say that REST API is not about "outbound calls" but "observing service" provided by a given application, basically in REST the actions (HTTP verbs) that can be performed over a resource (with a given URI).
Going a bit in detail on your situation, and if I understand correctly, you have some call to service 1, which triggers a call to service 2, and which replies back to service 1. This call from service 1 to the REST API of service 2, and in many cases it could wait for the response from service 2 (service 2 will simply reply to service 1 call). We could imagine more complicated behaviors where this call is not "blocking", which would lead to the need of defining a new call "back" from service 2 to service 1 API when service 2 finishes some computation (triggered by service 1 call). In this last case that could be implemented via a kind of "call-back" call from service 2 to some API endpoint of service 1.
Hope this helps bringing some light to your situation.
Upvotes: 3