golang-grpc-realworld-example
golang-grpc-realworld-example copied to clipboard
A real world backend API built with golang + grpc
Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
Demo RealWorld
This codebase was created to demonstrate a fully fledged fullstack application built with golang/grpc including CRUD operations, authentication, routing, pagination, and more.
How it works

-
Using grpc-gateway as reverse-proxy server which translates a RESTful JSON API into gRPC.
-
Using Go to implement realworld backend server.
-
Using MySQL to store data.
Getting started
The app listens and serves on 0.0.0.0:3000.
-
docker-compose
$ docker-compose up -d -
local
- Install Go 1.13+, MySQL
- set environment variables to connect database like this.
$ go run server.go # run grpc server $ go run gateway/gateway.go # run grpc-gateway server
Unit test
-
docker-compose
$ docker-compose run app make test -
local
$ make test
E2E test
$ make e2etest
TODOs
-
[x] Users and Authentication
- [x]
POST /user/login: Existing user login - [x]
POST /users: Register a new user - [x]
GET /user: Get current user - [x]
PUT /user: Update current user
- [x]
-
[x] Profiles
- [x]
GET /profiles/{username}: Get a profile - [x]
POST /profiles/{username}/follow: Follow a user - [x]
DELETE /profiles/{username}/follow: Unfollow a user
- [x]
-
[x] Articles
- [x]
GET /articles/feed: Get recent articles from users you follow - [x]
GET /articles: Get recent articles globally - [x]
POST /articles: Create an article - [x]
GET /articles/{slug}: Get an article - [x]
PUT /articles/{slug}: Update an article - [x]
DELETE /articles/{slug}: Delete an article
- [x]
-
[x] Comments
- [x]
GET /articles/{slug}/comments: Get comments for an article - [x]
POST /articles/{slug}/comments: Create a comment for an article - [x]
DELETE /articles/{slug}/comments/{id}: Delete a comment for an article
- [x]
-
[x] Favorites
- [x]
POST /articles/{slug}/favorite: Favorite an article - [x]
DELETE /articles/{slug}/favorite: Unfavorite an article
- [x]
-
[x] Deafult
-
[x]
GET /tags: Get tags -
[x] E2E test
┌─────────────────────────┬───────────────────┬───────────────────┐ │ │ executed │ failed │ ├─────────────────────────┼───────────────────┼───────────────────┤ │ iterations │ 1 │ 0 │ ├─────────────────────────┼───────────────────┼───────────────────┤ │ requests │ 31 │ 0 │ ├─────────────────────────┼───────────────────┼───────────────────┤ │ test-scripts │ 46 │ 0 │ ├─────────────────────────┼───────────────────┼───────────────────┤ │ prerequest-scripts │ 17 │ 0 │ ├─────────────────────────┼───────────────────┼───────────────────┤ │ assertions │ 345 │ 0 │ ├─────────────────────────┴───────────────────┴───────────────────┤ │ total run duration: 17.5s │ ├─────────────────────────────────────────────────────────────────┤ │ total data received: 8.73KB (approx) │ ├─────────────────────────────────────────────────────────────────┤ │ average response time: 33ms [min: 10ms, max: 150ms, s.d.: 31ms] │ └─────────────────────────────────────────────────────────────────┘
