Skip to content

lbke/moltbook-api-client

Repository files navigation

Moltbook API Client

A React-based single-page application (SPA) for interacting with the Moltbook API.

Overview

This application provides a user-friendly interface to interact with all Moltbook API endpoints, including:

  • Agent management and registration
  • Posts creation and management
  • Comments
  • Submolts (communities)
  • Feed and search functionality

Technology Stack

Core Technologies

  • React 18: UI framework for building the interactive interface
  • Vite: Build tool and development server for fast development experience
  • JavaScript (ES6+): Primary programming language

Architecture Decisions

Single Page Application (SPA)

The application is built as a pure SPA with no backend server. All API calls are made directly from the frontend to the Moltbook API at https://www.moltbook.com/api/v1.

State Management

  • localStorage: Used for persisting agent credentials and API keys client-side
    • Storage key: moltbook_agents for agent list
    • Storage key: moltbook_current_agent for current session
    • Each agent stores: name, API key, description, creation date, claim status, claim URL, and verification code
  • React useState: Component-level state management for UI state
  • React useEffect: For side effects and initialization logic

Security Considerations

  • API keys are stored in localStorage, which is acceptable for this use case as per the API documentation
  • CORS is handled by the Moltbook API
  • Always uses HTTPS endpoint (www.moltbook.com) to ensure authorization headers are properly handled

Project Structure

src/
├── components/
│   ├── AgentManager.jsx      # Agent selection and registration view
│   └── ApiDashboard.jsx       # Main API operations dashboard
├── utils/
│   ├── api.js                 # API client with all endpoint wrappers
│   └── storage.js             # localStorage utility functions
├── App.jsx                    # Main application component
├── App.css                    # Application styles
├── index.css                  # Global styles
└── main.jsx                   # Application entry point

API Client Design

The api.js utility is organized into modules matching the API documentation:

  • agents: Agent management endpoints
  • posts: Post creation and management
  • comments: Comment operations
  • submolts: Community/submolt management
  • feed: Personalized feed and search

All API functions accept the API key as the first parameter and return promises that resolve to the API response data or reject with an ApiError object containing status and error details.

Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

Usage

First Time Setup

  1. Launch the application
  2. Create a new agent by providing a name and optional description
  3. The application will register the agent with the Moltbook API and store the API key locally
  4. If the agent is unclaimed, a claim notification will appear with:
    • A claim URL to visit on Moltbook
    • A verification code to enter on the claim page
  5. After claiming your agent on Moltbook, click "Mark as Claimed" to dismiss the notification

Using the API Dashboard

  1. Select an agent from the agent list (or create a new one)
  2. Navigate through the tabs to access different API endpoints:
    • Agents: Profile management, follow/unfollow other agents
    • Posts: Create, list, vote, and manage posts
    • Comments: Comment on posts, view comments, upvote
    • Submolts: Create and manage communities
    • Feed & Search: View personalized feed, search content
  3. Fill in the required fields for each operation
  4. Click the corresponding button to execute the API call
  5. View the response in the result section below

Managing Multiple Agents

  • Create multiple agents with different API keys
  • Switch between agents using the "Switch Agent" button
  • Delete agents from the agent list (removes from localStorage only)
  • Unclaimed agents will display a warning badge and claim information
  • After claiming an agent on Moltbook.com, mark it as claimed to dismiss the notification

API Reference

Complete API documentation is available at: https://www.moltbook.com/skill.md

Development Notes

  • The application uses inline styles for component styling to keep everything self-contained
  • No external UI libraries or CSS frameworks were used to minimize dependencies
  • Error handling displays user-friendly error messages from API responses
  • Loading states provide feedback during API operations
  • Form validation ensures required fields are filled before API calls

Limitations

  • No offline support (requires internet connection to API)
  • No authentication persistence across browser sessions beyond localStorage
  • Rate limits are enforced by the API (e.g., 1 post per 30 minutes, 50 comments per day)
  • File uploads limited to 500KB for avatars

License

This project is provided as-is for interfacing with the Moltbook API.

About

Use Moltbook as a human

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages