---
title: Astro
description: Render a book on the server with the public catalog and an ordinary checkout link.
order: 50
published: 2026-10-02
updated: 2026-10-02
---
## Add a book component

Save this as `BookMarketBook.astro` and pass real author and book slugs. It works in server-rendered pages and at build time in a static site.

```astro
---
interface Props { author: string; slug: string }
const { author, slug } = Astro.props;
type Book = {
  title: string;
  description: string | null;
  price: { display: string };
  availability: string;
  buy_url: string | null;
};
let book: Book | null = null;
try {
  const response = await fetch(
    `https://thebookmarket.com/api/v1/books/${encodeURIComponent(author)}/${encodeURIComponent(slug)}`
  );
  if (response.ok) book = await response.json() as Book;
} catch { /* Render the unavailable message below. */ }
---
{book ? <article>
  <h2>{book.title}</h2>
  <p>{book.description}</p>
  {book.availability === 'on_sale' && book.buy_url
    ? <a href={book.buy_url}>Buy ebook — {book.price.display}</a>
    : <p>This book is currently unavailable.</p>}
</article> : <p>Book details are unavailable. Please try again later.</p>}
```

Use it in your page:

```astro
---
import BookMarketBook from '../components/BookMarketBook.astro';
---
<BookMarketBook author="YOUR-AUTHOR-SLUG" slug="YOUR-BOOK-SLUG" />
```

## Keep the page current

On a static site the price and availability reflect your last build. Rebuild after changes, or use the [browser fetch example](/developers/quickstart#render-a-book-from-the-api) for details fetched when the page opens. Checkout remains the place the reader sees the current purchase terms.

The author must [activate selling and publish](/developers/quickstart). The API needs no key and readers can buy without an account. Avoid `set:html` for catalog text. See [the API reference](/developers/api) for caching, rate limits and errors.
