Is it possible to call grpc services in refit?

167 views Asked by At

I use refit to call my services. I want to use grpc services in my code in the APIs that refit calls. Is it possible? And I did not see anything about this problem on the stackoverflow. No clue about grpc was found in the refit code available on github thanks for read my pronblem.

1

There are 1 answers

0
dan-kli On

Currently you cannot call gRPC with Refit. Refit is build for REST APIs, but gRPC is not built on REST, it is built on the concept of Remote Procedure Calls (RPC). There are many articles on the web that highlight the differences between REST and RPC, like this one.


If you are looking for something similar like Refit for gRPC in C#, then what you are looking for is protobuf-net. It allows you to define high-level interfaces to gRPC services similar to refit. Looking at the following example code from the Refit Github repo:

// REST + Refit
public interface IGitHubApi
{
    [Get("/users/{user}")]
    Task<User> GetUser(string user);
}

You could define a very similar interface to a gRPC service using protobuf-net as follows:

// gRPC + protobuf-net
[ServiceContract]
public interface IGitHubApi
{
    [OperationContract]
    Task<User> GetUser(string user);
}