Skip to content

This is a gRPC server project that uses gRPC-Gateway to create a reverse-proxy server. It uses protobuf service definitions and provides basic arithmetic operations, such as addition, division, multiplication, and subtraction, for two integers.

License

Notifications You must be signed in to change notification settings

iamrajiv/basic-arithmetic-grpc-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Basic Arithmetic gRPC Server

Simple basic arithmetic gRPC server which uses gRPC-Gateway

About

This is a gRPC server project that uses gRPC-Gateway to create a reverse-proxy server. It uses protobuf service definitions and provides basic arithmetic operations, such as addition, division, multiplication, and subtraction, for two integers.

For additional resources on gRPC-Gateway, take a look at Hello World gRPC-Gateway, a basic program that employs gRPC-Gateway. I developed this project while contributing to gRPC-Gateway during Google Season of Docs 2020 to help people become familiar with the framework.

All the tutorials related to Hello World gRPC-Gateway have been added to the gRPC-Gateway documentation website.

The folder structure of the project is as follows:

.
├── LICENSE
├── Makefile
├── README.md
├── assets
│   └── basic-arithmetic-grpc-server.svg
├── buf.gen.yaml
├── buf.yaml
├── go.mod
├── go.sum
├── main.go
└── proto
    ├── arithmetic
    │   ├── arithmetic.pb.go
    │   ├── arithmetic.pb.gw.go
    │   ├── arithmetic.proto
    │   ├── arithmetic.swagger.json
    │   └── arithmetic_grpc.pb.go
    └── google
        └── api
            ├── annotations.proto
            └── http.proto

Usage

Installation

Before running this project, we need to install the required Go packages. To do this, run the following command:

make install

Generating stubs

We can generate the stubs for the project using the following command:

make generate

Cleaning stubs

To delete the stubs, use the following command:

make clean

Running the server

To run the server, use the following command:

go run main.go

Sending HTTP Requests

To send an HTTP POST request to the server, use cURL with the following command:

Please note that the project only supports fundamental arithmetic operations, including addition, division, multiplication, and subtraction. However, these operations are exclusively intended for integer values and do not support non-integer values.

For /v1/arithmetic/add endpoint:

curl -k  -X POST "http://localhost:8090/v1/arithmetic/add" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"a\": \"15\",  \"b\": \"17\"}"

The server will respond with the following message:

{"result":"32"}

For /v1/arithmetic/sub endpoint:

curl -k  -X POST "http://localhost:8090/v1/arithmetic/sub" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"a\": \"15\",  \"b\": \"17\"}"

The server will respond with the following message:

{"result":"-2"}

For /v1/arithmetic/mul endpoint:

curl -k  -X POST "http://localhost:8090/v1/arithmetic/mul" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"a\": \"15\",  \"b\": \"17\"}"

The server will respond with the following message:

{"result":"255"}

For /v1/arithmetic/div endpoint:

curl -k  -X POST "http://localhost:8090/v1/arithmetic/div" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"a\": \"15\",  \"b\": \"3\"}"

The server will respond with the following message:

{"result":"5"}

Swagger UI

We can view and test the API using the Swagger UI at the following link: https://app.swaggerhub.com/apis/iamrajiv/Basic_Arithmetic_gRPC_Server/2.

License

MIT

About

This is a gRPC server project that uses gRPC-Gateway to create a reverse-proxy server. It uses protobuf service definitions and provides basic arithmetic operations, such as addition, division, multiplication, and subtraction, for two integers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published