Create categoryv1.0.0 · JSON Schema
Creates a category in the Catalog.
1. Create a New Book Category
A backoffice catalog manager adds a “Science Fiction” category to organize catalog listings.
Payload details
name: Required non-empty category name.
Example payload
{ "name": "Science Fiction"}Using this example
Returns 201 Created with the created Category JSON payload and invalidates the categories list cache.
using BookWorm.Chassis.Utilities.Configurations;using BookWorm.Constants.Aspire;using Refit;
public interface ICatalogApiClient{ [Post("/api/v1/categories")] Task<CategoryResponse> CreateCategoryAsync( [Body] CreateCategoryRequest request, CancellationToken cancellationToken = default );}
public sealed record CreateCategoryRequest(string Name);
// 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 invocationvar category = await catalogApiClient.CreateCategoryAsync( new("Science Fiction"), cancellationToken);import categoriesApiClient from "@workspace/api-client/catalog/categories";import useCreateCategory from "@workspace/api-hooks/catalog/categories/useCreateCategory";
// 1. Direct @workspace/api-client (Axios) callconst category = await categoriesApiClient.create({ name: "Science Fiction",});
// 2. React / TanStack Query hook (@workspace/api-hooks)const { mutate: createCategory, isPending } = useCreateCategory({ onSuccess: (created) => { console.log(`Created category ${created.id}: ${created.name}`); },});
createCategory({ name: "Science Fiction" });1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "CreateCategory",
4 "description": "Payload for CreateCategory.",
5 "type": "object",
6 "additionalProperties": false,
7 "required": ["name"],
8 "properties": {
9 "name": {
10 "type": "string",
11 "minLength": 1,
12 "description": "Display name of the catalog resource."
13 }
14 }
15}
16