I'm trying to design an API for our app. We're going to have to support a REST API, but I'd really also like to have a gRPC API as well.
The question is -- how to design them so they're roughly the same? And in particular, what do we do about verbs / actions?
The standard rule in designing a REST API is to use nouns, not verbs. This blog post explains it well:
https://apigee.com/about/blog/technology/restful-api-design-nouns-are-good-verbs-are-badYou should have http methods that look like this:
GET /dogs/1234 // get a dog
POST /dogs // create a dog
DELETE /dogs/1234 // delete a dog
and not this:
/createDog
/deleteDog
Unfortunately, gRPC makes standard REST-style calls impossible, because it doesn't support path parameters, and as far as I can tell it always uses the POST http method.
So, I have two ways to modify the REST calls to make them gRPC compatible:
1. Put a verb in the endpoint:
POST /dogs/create body={ id: 1234, name="Fluffy" }
or 2. Put the verb in the body:
POST /dogs body={ action:"create", id: 1234, name="Fluffy" }
What do most people do?