liveBook · Manning

Endpoint

As explained in gRPC Microservices in Go

A gRPC endpoint is a network-accessible interface through which a client communicates with a gRPC service.

A gRPC endpoint gives a client a way to call a service operation. In an Order service, exposing Create takes more than starting a server: the server must listen on a TCP port, register the Order service, and provide a handler that connects the request to application logic. section 4.2.6

Keep the network boundary separate from the application:

  • Register the gRPC adapter with the server. Enable reflection in development to test calls with grpcurl; otherwise, supply grpcurl with the relevant .proto files. section 4.2.6
  • In Create, convert CreateOrderRequest items into domain order items, call APIPort.PlaceOrder, and return the resulting order ID or error. section 4.2.6
  • For an outbound call, configure the Payment service endpoint separately. The Order service reads PAYMENT_SERVICE_URL, fails startup if it is missing, and uses it to initialize the payment adapter. section 5.2.5
func (a Adapter) Create(ctx context.Context, request *order.CreateOrderRequest) (*order.CreateOrderResponse, error) {  #1
    var orderItems []domain.OrderItem
    for _, orderItem := range request.OrderItems {                     #2
        orderItems = append(orderItems, domain.OrderItem{
            ProductCode: orderItem.ProductCode,
            UnitPrice:   orderItem.UnitPrice,
            Quantity:    orderItem.Quantity,
        })
    }
    newOrder := domain.NewOrder(request.UserId, orderItems)            #3
    result, err := a.api.PlaceOrder(newOrder)                          #4
    if err != nil {
        return nil, err
    }
    return &order.CreateOrderResponse{OrderId: result.ID}, nil 
}

The Create handler shows where the network request becomes a domain order and where application errors return to the gRPC caller. section 4.2.6

Endpoint access also has operational consequences. Public APIs need clear names for consumers and may need authentication, authorization, and rate limiting to protect server resources. Other endpoint URLs serve different purposes: tests obtain a running MySQL container’s connection URL, while an OpenTelemetry Collector endpoint accepts metrics from gRPC microservices. These are addresses to connect to, not additional Order service methods. section 1.4.5 section 7.3.2 section 9.3.2

How gRPC Microservices in Go covers it

How deep it goes
Works through server registration and a Create handler; configures a Payment endpoint URL but defers its automatic discovery.
Examples
Shows an Order Create handler, grpcurl testing, PAYMENT_SERVICE_URL configuration, and a Collector endpoint for metrics.
What it assumes
Assumes an Order application port and generated gRPC models; shows how to attach them to a listening server.
What you can do after
Build it from scratch by registering an Order gRPC handler, mapping its request to application logic, and configuring an outbound Payment address.
How it connects
Connects gRPC adapters, application ports, domain models, service configuration, API gateways, and observability.

Also explained in

Compare how 26 books explain endpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.