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.
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.
/v1/users
Create a new user with unique Username, email and other such details./v1/users
Lists all the users present at the given time./v1/users/{username}
Update the User with specified username./v1/users/{username}
Deletes the User with specified username./v1/users/{username}
Fetch the details of User with specified username.A simple authentication service for User verification.
/v1/auth/login
Takes user input (Username & Password) to generate a token.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.
/v1/movies
Adds a new Movie with unique Name, Tags, Summary and other such details. This returns the generated id for the inserted Movie./v1/movies
Lists all the Movies present at the given time./v1/movies/{id}
Update an already present Movie with new values./v1/movies/{id}
Delete an existing Movie with given ID./v1/movies/{id}
Fetches the movie with given ID.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
and QueriesPerInterval
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.
git clone github.com/AkashGit21/ms-template
make gen
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.
git clone github.com/AkashGit21/ms-template
make docker-build
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
git clone github.com/AkashGit21/ms-template
ms-server
in the same directory.
make build