puerto 0.17.0

Puerto — Rust full-stack DDD framework CLI. Scaffolds Clean Architecture projects with auto-wired DI, SQLx support, and zero manual wiring. Formerly puerto-framework.
import createClient, { type Client, type ClientOptions } from "openapi-fetch";
import type { paths } from "./schema";

/** The typed API client. `paths` is generated from the backend's spec (`make web/sync`). */
export type ApiClient = Client<paths>;

/** `/api` is the backend: proxied to `:8080` by Vite in development. */
export function createApiClient(options: ClientOptions = {}): ApiClient {
  return createClient<paths>({ baseUrl: "/api", ...options });
}

/**
 * The machine-readable code of a failed call: the `ErrorResponse.name` the API answered, or
 * `http.<status>` for a body that is not one (a proxy error, poem's own `400`).
 */
export function apiErrorCode(error: unknown, response: Response): string {
  if (typeof error === "object" && error !== null && "name" in error) {
    const { name } = error;
    if (typeof name === "string") return name;
  }
  return `http.${response.status}`;
}