Create bookv1.0.0 · JSON Schema
Creates a book listing and returns its generated UUID.
1. Create a Book Listing with Promotional Price and Cover Image
A backoffice catalog manager publishes “The Left Hand of Darkness” with a regular price, promotional sale price, category, publisher, author, and a JPEG cover image via multipart/form-data.
Payload details
name: Required book title (max 50 chars).description: Required book summary.price: Required regular decimal price (> 0).priceSale: Optional promotional price (> 0and<= price).categoryId,publisherId: Required existing UUIDs.authorIds: Required non-empty array of author UUIDs.image: Optional cover image (image/jpeg,image/png, orimage/webp, max 1 MB).
Using this example
Returns 201 Created with the generated UUIDv7 BookId and Location: /api/v1/books/{id} header, invalidates FusionCache book tags, and queues the book for vector indexing.
using BookWorm.Chassis.Utilities.Configurations;using BookWorm.Constants.Aspire;using Refit;
public interface ICatalogApiClient{ [Multipart] [Post("/api/v1/books")] Task<Guid> CreateBookAsync( [AliasAs("name")] string name, [AliasAs("description")] string description, [AliasAs("price")] decimal price, [AliasAs("priceSale")] decimal? priceSale, [AliasAs("categoryId")] Guid categoryId, [AliasAs("publisherId")] Guid publisherId, [AliasAs("authorIds")] IEnumerable<Guid> authorIds, [AliasAs("image")] StreamPart? image = null, CancellationToken cancellationToken = default );}
// DI registration following BookWorm.Chassis Refit patternbuilder.Services .AddRefitGeneratedClient<ICatalogApiClient>(settings, Services.Catalog) .ConfigureHttpClient(client => client.BaseAddress = new($"https+http://{Services.Catalog}")) .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(5) } );
// Typed invocationawait using var coverStream = File.OpenRead("cover.jpg");var bookId = await catalogApiClient.CreateBookAsync( name: "The Left Hand of Darkness", description: "A science-fiction novel by Ursula K. Le Guin set on the icy planet Gethen.", price: 18.99m, priceSale: 14.99m, categoryId: Guid.Parse("01960a1b-1000-7000-8a9b-0c1d2e3f4a01"), publisherId: Guid.Parse("01960a1b-2000-7000-8a9b-0c1d2e3f4a02"), authorIds: [Guid.Parse("01960a1b-3000-7000-8a9b-0c1d2e3f4a03")], image: new StreamPart(coverStream, "cover.jpg", "image/jpeg"), cancellationToken: cancellationToken);import booksApiClient from "@workspace/api-client/catalog/books";import useCreateBook from "@workspace/api-hooks/catalog/books/useCreateBook";
const request = { name: "The Left Hand of Darkness", description: "A science-fiction novel by Ursula K. Le Guin set on the icy planet Gethen.", price: 18.99, priceSale: 14.99, categoryId: "01960a1b-1000-7000-8a9b-0c1d2e3f4a01", publisherId: "01960a1b-2000-7000-8a9b-0c1d2e3f4a02", authorIds: ["01960a1b-3000-7000-8a9b-0c1d2e3f4a03"], image: coverFile,};
// 1. Direct @workspace/api-client (Axios multipart/form-data) callconst createdBook = await booksApiClient.create(request);
// 2. React / TanStack Query hook (@workspace/api-hooks)const { mutate: createBook, isPending } = useCreateBook({ onSuccess: () => { console.log("Book listing created"); },});
createBook(request);1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "CreateBook",
4 "description": "Multipart payload for creating a book listing.",
5 "type": "object",
6 "additionalProperties": false,
7 "required": ["name", "price", "categoryId", "publisherId", "authorIds"],
8 "properties": {
9 "name": {
10 "type": "string",
11 "minLength": 1,
12 "description": "Book title."
13 },
14 "description": {
15 "type": "string",
16 "minLength": 1,
17 "description": "Book description."
18 },
19 "image": {
20 "type": ["string", "null"],
21 "contentEncoding": "base64",
22 "description": "Optional cover image file."
23 },
24 "price": {
25 "type": "number",
26 "minimum": 0,
27 "description": "Regular price."
28 },
29 "priceSale": {
30 "type": ["number", "null"],
31 "minimum": 0,
32 "description": "Optional sale price."
33 },
34 "categoryId": {
35 "type": "string",
36 "format": "uuid",
37 "description": "Category UUID."
38 },
39 "publisherId": {
40 "type": "string",
41 "format": "uuid",
42 "description": "Publisher UUID."
43 },
44 "authorIds": {
45 "type": "array",
46 "minItems": 1,
47 "items": {
48 "type": "string",
49 "format": "uuid",
50 "description": "A UUID identifying the resource."
51 },
52 "description": "Authors associated with the book."
53 }
54 }
55}
56