Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamrajiv/basic-arithmetic-grpc-server
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.
https://github.com/iamrajiv/basic-arithmetic-grpc-server
go grpc grpc-gateway protobuf rest
Last synced: 4 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/iamrajiv/basic-arithmetic-grpc-server
- Owner: iamrajiv
- License: mit
- Created: 2020-12-13T08:44:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-06T08:00:16.000Z (over 1 year ago)
- Last Synced: 2024-10-03T10:14:58.781Z (4 months ago)
- Topics: go, grpc, grpc-gateway, protobuf, rest
- Language: Go
- Homepage: https://app.swaggerhub.com/apis/iamrajiv/Basic_Arithmetic_gRPC_Server/2
- Size: 123 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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](https://github.com/iamrajiv/helloworld-grpc-gateway), a basic program that employs gRPC-Gateway. I developed this project while contributing to [gRPC-Gateway](https://github.com/grpc-ecosystem/grpc-gateway) during [Google Season of Docs 2020](https://github.com/iamrajiv/GSoD-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](https://grpc-ecosystem.github.io/grpc-gateway/docs/tutorials/).
The folder structure of the project is as follows:
```shell
.
├── 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
└── 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:
```shell
make install
```#### Generating stubs
We can generate the stubs for the project using the following command:
```shell
make generate
```#### Cleaning stubs
To delete the stubs, use the following command:
```shell
make clean
```#### Running the server
To run the server, use the following command:
```shell
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:
```shell
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:
```shell
{"result":"32"}
```For `/v1/arithmetic/sub` endpoint:
```shell
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:
```shell
{"result":"-2"}
```For `/v1/arithmetic/mul` endpoint:
```shell
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:
```shell
{"result":"255"}
```For `/v1/arithmetic/div` endpoint:
```shell
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:
```shell
{"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](https://app.swaggerhub.com/apis/iamrajiv/Basic_Arithmetic_gRPC_Server/2).
## License
[MIT](https://github.com/iamrajiv/basic-arithmetic-grpc-server/blob/main/LICENSE)