Get basket over gRPCv1.0.0 · Protobuf Schema
Returns the current basket through the basket.v1 gRPC contract.
1. Retrieve Customer Basket During Order Checkout
During CreateOrder, Ordering API invokes basket.v1.BasketGrpcService/GetBasket on Basket API using an On-Behalf-Of (OBO) Entra ID user token to read the authenticated customer’s basket items.
Payload details
- Request (
google.protobuf.Empty): No fields; Basket API resolves the shopper identity from the propagated bearer token. - Response (
GetBasketResponse):id: Basket identifier string (empty string if no basket exists).items: RepeatedItemmessages containingid(book UUID) andquantity(int32).
Using this example
Returns StatusCode.OK with GetBasketResponse populated from Redis (id and items), or an empty GetBasketResponse (id = "", items = []) when no basket exists for the customer.
using BookWorm.Basket.Grpc.Services;using BookWorm.Chassis.Security.TokenExchange;using BookWorm.Chassis.Utilities;using BookWorm.Chassis.Utilities.Configurations;
// 1. DI registration in Ordering API (src/Services/Ordering/BookWorm.Ordering/Grpc/Extensions.cs)builder.Services .AddGrpcServiceReference<BasketGrpcService.BasketGrpcServiceClient>( HttpUtilities .AsUrlBuilder() .WithScheme(builder.GetScheme()) .WithHost(Constants.Aspire.Services.Basket) .Build(), HealthStatus.Degraded ) .AddUserTokenExchange(Constants.Aspire.Services.Basket);
// 2. Typed gRPC client invocation (src/Services/Ordering/BookWorm.Ordering/Grpc/Services/Basket/BasketService.cs)internal sealed class BasketService(BasketGrpcService.BasketGrpcServiceClient service) : IBasketService{ public async Task<GetBasketResponse> GetBasket(CancellationToken cancellationToken = default) { var result = await service.GetBasketAsync( new(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken );
return result; }}1edition = "2023";
2
3import "google/protobuf/empty.proto";
4
5option csharp_namespace = "BookWorm.Basket.Grpc.Services";
6
7package basket.v1;
8
9service BasketGrpcService {
10 rpc GetBasket (google.protobuf.Empty) returns (GetBasketResponse);
11}
12
13message GetBasketResponse {
14 string id = 1;
15 repeated Item items = 2;
16}
17
18message Item {
19 string id = 1;
20 int32 quantity = 2;
21}
22