Getting started

Quickstart

Create a client instance and fetch your first blog list in under a minute.

  1. 1
    Instantiate the client

    Create a single shared client at the module level so it is reused across requests.

    Code
    import { BlogClient } from "blogjs-space";
    
    const client = new BlogClient({
      apiKey: "your-project-api-key",
    });
  2. 2
    Fetch blogs in a server component
    Code
    // app/blogs/page.tsx
    export default async function BlogsPage() {
      const result = await client.getBlogs({
        page: 1,
        limit: 10,
      });
    
      return (
        <ul>
          {result.data.map((blog) => (
            <li key={blog.slug}>{blog.title}</li>
          ))}
        </ul>
      );
    }
  3. 3
    Fetch a single blog by slug
    Code
    // app/blogs/[slug]/page.tsx
    export default async function BlogPage({
      params,
    }: {
      params: Promise<{ slug: string }>;
    }) {
      const { slug } = await params;
      const blog = await client.getBlogBySlug(slug);
    
      if (!blog) return <p>Not found</p>;
    
      return <h1>{blog.title}</h1>;
    }