Skip to content

Learning how to handle errors sent out by a gRPC server in a REST Gateway and sending meaningful error responses to clients

Notifications You must be signed in to change notification settings

thegeorgenikhil/handling-grpc-errors-in-rest-gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handling gRPC Errors in a REST API Gateway(POC)

Learning how to handle errors sent out by a gRPC server in a REST Gateway and sending meaningful error responses to clients

The REST API Gateway is running on localhost:8082 and the gRPC server is running on localhost:8081.

How to run

  1. Start the gRPC server
make start_grpc
  1. Start the Gateway
make start_gateway

gRPC Server

service CalculatorService {
    rpc DivideNumbers(DivideNumbersRequest) returns (DivideNumbersResponse);
}

// Divide number_one by number_two
message DivideNumbersRequest {
    float number_one = 1;
    float number_two = 2;
}

message DivideNumbersResponse {
    int32 code = 1;
    float answer = 2;
}

REST API Gateway

Endpoint: /calculator/divide

Method: POST

Request Body:

{
  "number_one": 10,
  "number_two": 0
}

Success Response:

{
  "code": 200,
  "answer": 0.01
}

Error Response:

// Errors out when number_two is 0 (Division by zero)
{
  "error": true,
  "message": "division by zero not possible"
}

About

Learning how to handle errors sent out by a gRPC server in a REST Gateway and sending meaningful error responses to clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published