Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST vs RPC for a C++ API

Tags:

c++

rest

rpc

I am writing a C++ API which is to be used as a web service. The functions in the API take in images/path_to_images as input parameters, process them, and give a different set of images/paths_to_images as outputs. I was thinking of implementing a REST interface to enable developers to use this API for their projects (independent of whatever language they'd like to work in). But, I understand REST is good only when you have a collection of data that you want to query or manipulate, which is not exactly the case here. [The collection I have is of different functions that manipulate the supplied data.]

So, is it better for me to implement an RPC interface for this, or can this be done using REST itself?

like image 473
Giridhar Murali Avatar asked Dec 04 '25 06:12

Giridhar Murali


1 Answers

Like lcfseth, I would also go for REST. REST is indeed resource-based and, in your case, you might consider that there's no resource to deal with. However, that's not exactly true, the image converter in your system is the resource. You POST images to it and it returns new images. So I'd simply create a URL such as:

POST http://example.com/image-converter

You POST images to it and it returns some array with the path to the new images.

Potentially, you could also have:

GET http://example.com/image-converter

which could tell you about the status of the image conversion (assuming it is a time consuming process).

The advantage of doing it like that is that you are re-using HTTP verbs that developers are familiar with, the interface is almost self-documenting (though of course you still need to document the format accepted and returned by the POST call). With RPC, you would have to define new verbs and document them.

like image 80
laurent Avatar answered Dec 05 '25 22:12

laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!