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-bad

You 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?

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/56ff06f1-7cb7-47e4-87ed-ca0f71528dbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to