January 2020
Intermediate to advanced
640 pages
16h 56m
English
A unary RPC is equivalent to the request-response model that's used in traditional RESTful APIs. In the following example, we are defining a service with the name AccountService that exposes a CreateAccount method that receives CreateAccountRequest as input and returns a CreateAccountResponse to the caller:
message CreateAccountRequest { string user_name = 1; string password = 2; string email = 3;}message CreateAccountResponse { string account_id = 1;}service AccountService { rpc CreateAccount (CreateAccountRequest) returns (CreateAccountResponse);}Defining the server handler is also quite similar to a regular RESTful API. Consider the following code:
var _ AccountServiceServer = (*server)(nil)func (*server) CreateAccount(_ ...