Goa supports both HTTP and gRPC. The transport mapping DSL allows you to define how your service methods are exposed over these protocols.
The HTTP DSL defines how your service methods map to HTTP endpoints. You can configure this at three levels:
Define global HTTP settings that apply to all services:
API("bookstore", func() {
HTTP(func() {
Path("/api/v1") // Global prefix for all endpoints
})
})
Configure HTTP properties for all methods in a service:
Service("books", func() {
HTTP(func() {
Path("/books") // Service-wide path prefix
Parent("store") // Parent service for path nesting
})
})
Define specific HTTP behavior for individual methods:
Method("show", func() {
HTTP(func() {
GET("/{id}") // HTTP method and path
Response(StatusOK) // Success response code
})
})
The HTTP DSL provides several features for configuring endpoints:
Path Parameters
Query Parameters
Headers
Response Codes
The gRPC DSL defines how your service methods map to gRPC procedures. Like HTTP, it can be configured at multiple levels.
Message Mapping
Status Codes
Metadata
Here are some common transport mapping patterns:
Service("users", func() {
HTTP(func() {
Path("/users")
})
Method("list", func() {
HTTP(func() {
GET("/") // GET /users
})
})
Method("show", func() {
HTTP(func() {
GET("/{id}") // GET /users/{id}
})
})
})
Services can support both HTTP and gRPC:
Method("create", func() {
// HTTP mapping
HTTP(func() {
POST("/")
Response(StatusCreated)
})
// gRPC mapping
GRPC(func() {
Response(CodeOK)
})
})
HTTP Design
gRPC Design
General Tips
Each transport protocol has its own way of representing errors: