Skip to content

Bookstore

The go-zero official example: an API gateway that delegates to a backend RPC service, using MySQL for storage.

Client → bookstore-api (HTTP) → bookstore-rpc (gRPC) → MySQL
Terminal window
git clone https://github.com/zeromicro/go-zero.git
cd go-zero/example/bookstore
ServicePortDescription
api/8888HTTP gateway
rpc/8080gRPC book service
Terminal window
cd rpc
go run bookstore.go -f etc/bookstore.yaml
Terminal window
cd api
go run bookstore.go -f etc/bookstore-api.yaml
Terminal window
# Add a book
curl -X POST http://localhost:8888/add \
-H "Content-Type: application/json" \
-d '{"book":"The Go Programming Language","price":42}'
# Check stock
curl "http://localhost:8888/check?book=The+Go+Programming+Language"
  • API gateway routing to RPC backend
  • goctl model generation from MySQL DDL
  • ServiceContext wiring of RPC client