This repository tries to include most of the boilerplate code needed to develop gRPC APIs using Go and gRPC. Some of the important features are: REST/HTTP gateway(developed usig grpc-gateway), Logging, Authentication/Authorization, Rate Limiting, etc.
-
gRPC API alongwith the REST/HTTP API built using grpc-gateway.
-
Services
Currently, three services are supported:
-
This enables the user to perform actions such as: creating User, deleting the User, updating his/her info. and fetch Users by Id or whole. The operations are authorized depending on User permissions and such.
- POST
/v1/users
Create a new user with unique Username, email and other such details. - GET
/v1/users
Lists all the users present at the given time. - PUT
/v1/users/{username}
Update the User with specified username. - DELETE
/v1/users/{username}
Deletes the User with specified username. - GET
/v1/users/{username}
Fetch the details of User with specified username.
- POST
-
A simple authentication service for User verification.
- POST
/v1/auth/login
Takes user input (Username & Password) to generate a token.
- POST
-
This enables the user to perform following activities: inserting a Movie, deleting Movie, updating its info. and/or fetching Movies by Id or as a whole. The operations are authorized depending on User permissions and such.
- POST
/v1/movies
Adds a new Movie with unique Name, Tags, Summary and other such details. This returns the generated id for the inserted Movie. - GET
/v1/movies
Lists all the Movies present at the given time. - PUT
/v1/movies/{id}
Update an already present Movie with new values. - DELETE
/v1/movies/{id}
Delete an existing Movie with given ID. - GET
/v1/movies/{id}
Fetches the movie with given ID.
- POST
-
-
Unit Tests
IN PROGRESS
-
Documentation
Visit here to view the documentation of Services. Search for the service you like to explore (e.g: IdentityService-0.1.yaml, AuthService-0.1.yaml, or MovieService-0.1.yaml )
Documentation will be updated as per the modifications and changes in business logic. Also, the documentation is auto-generated. Hence, less focus may be there in some scenarios.
-
Rate Limiting
The middleware to rate limit requests has been applied. By default, it is 2requests/min. To modify the limit, update
RefreshDuration
andQueriesPerInterval
in this file. -
Pagination
The concept of pagination has been supported for List calls such as
GET v1/movies
.
Query Parameters such as page_size and page_token are supported for List calls. The response returns a next_page_token as well.
- Golang v1.16+
- go protobuf tools (to generate code from proto files)
-
Clone the repository to your desired location.
git clone github.com/AkashGit21/ms-template
-
Make changes to the proto files as per your need and run the below command to generate Go files.
make gen
-
Update the server and client with your business logic
-
To run the server, use the following command:
make run
The ms-template can be installed by building your local Docker image or simply by installing form source using Go.
The pre-requisite for this process is the requirement of Docker (to be installed locally). Hence, install Docker if not already installed.
-
Clone the repository to your desired location.
git clone github.com/AkashGit21/ms-template
-
Now, lets build the Docker image locally using:
make docker-build
-
Then, to run the container use:
make docker-run
Now, you should be able to access the REST API at localhost:8081
and gRPC API at localhost:8082
.
This will first build a docker image locally. Please keep calm as the process may take a few minutes. Then, it goes on to run the image in a container (in the background) and you shoul be able to check the container named ms-server
using docker ps
.
To stop the container, use:
make docker-stop
- Clone the repository to your desired location.
git clone github.com/AkashGit21/ms-template
- Run the following command to make an executable file named
ms-server
in the same directory.make build