Update basketv1.0.0 · JSON Schema
Replaces a basket's item collection with the supplied items.
1. Update Line-Item Quantities in an Existing Basket
An authenticated shopper adjusts the quantity of “The Left Hand of Darkness” and adds “Dune” to their existing basket.
Payload details
items: Required array representing the full replacement set of basket items.items[].id: Catalog book UUID string.items[].quantity: Updatedint32quantity for each item.
Example payload
{ "items": [ { "id": "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10", "quantity": 3 }, { "id": "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a12", "quantity": 1 } ]}Using this example
Returns 200 OK with the updated, catalog-enriched CustomerBasket JSON payload and replaces the stored items in Redis.
using BookWorm.Chassis.Utilities.Configurations;using BookWorm.Constants.Aspire;using Refit;
public interface IBasketApiClient{ [Put("/api/v1/baskets")] Task<CustomerBasketResponse> UpdateBasketAsync( [Body] UpdateBasketRequest request, CancellationToken cancellationToken = default );}
public sealed record BasketItemRequest(string Id, int Quantity);public sealed record UpdateBasketRequest(IReadOnlyList<BasketItemRequest> Items);
// DI registration following BookWorm.Chassis Refit patternbuilder.Services .AddRefitGeneratedClient<IBasketApiClient>(settings, Services.Basket) .ConfigureHttpClient(client => client.BaseAddress = new($"https+http://{Services.Basket}")) .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(5) } );
// Typed invocationvar updated = await basketApiClient.UpdateBasketAsync( new([ new("01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10", 3), new("01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a12", 1), ]), cancellationToken);import basketApiClient from "@workspace/api-client/basket/baskets";import useUpdateBasket from "@workspace/api-hooks/basket/useUpdateBasket";
// 1. Direct @workspace/api-client (Axios) callconst updatedBasket = await basketApiClient.update({ items: [ { id: "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10", quantity: 3 }, { id: "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a12", quantity: 1 }, ],});
// 2. React / TanStack Query hook (@workspace/api-hooks)const { mutate: updateBasket, isPending } = useUpdateBasket({ onSuccess: (basket) => { console.log(`Updated basket ${basket.id}`); },});
updateBasket({ items: [ { id: "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10", quantity: 3 }, { id: "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a12", quantity: 1 }, ],});1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "UpdateBasketCommand",
4 "type": "object",
5 "required": ["items"],
6 "properties": {
7 "items": {
8 "type": "array",
9 "items": {
10 "type": "object",
11 "required": ["id", "quantity"],
12 "properties": {
13 "id": {
14 "type": "string"
15 },
16 "quantity": {
17 "type": ["integer", "string"],
18 "format": "int32",
19 "pattern": "^-?(?:0|[1-9]\\d*)$"
20 }
21 }
22 }
23 }
24 }
25}
26