Skip to content

[Feature]: JavaScript/TypeScript Client Example for PowerMem HTTP API Server #181

@Teingi

Description

@Teingi

Describe your use case

JavaScript/TypeScript developers need a simple, practical client example to integrate PowerMem's intelligent memory capabilities into their web applications or Node.js backends. This example will demonstrate how to interact with the PowerMem HTTP API Server using native fetch API or popular HTTP libraries, enabling JavaScript/TypeScript applications to leverage PowerMem's memory management features.

Describe the solution you'd like

Create a simple JavaScript/TypeScript client example that demonstrates:

  1. Basic HTTP client setup:

    • Configuration for API base URL and API key
    • HTTP client initialization (using native fetch or minimal library)
    • Request/response handling with proper JSON serialization/deserialization
  2. Core memory operations:

    • Create memory (POST /api/v1/memories)
    • Search memories (POST /api/v1/memories/search)
    • List memories (GET /api/v1/memories)
    • Update memory (PUT /api/v1/memories/{memory_id})
    • Delete memory (DELETE /api/v1/memories/{memory_id})
  3. Project structure:

    • Simple Node.js project structure
    • TypeScript support (optional but recommended)
    • Main example file demonstrating all operations
    • PowerMem client class/module
    • Type definitions for requests/responses
    • Configuration management
    • Error handling examples
  4. Deliverables:

    • examples/javascript/ or examples/typescript/ directory with:
      • client.ts or client.js - PowerMem client class
      • example.ts or example.js - Main example demonstrating all operations
      • types.ts or types.d.ts - TypeScript type definitions (if using TS)
      • package.json - Node.js package configuration
      • tsconfig.json - TypeScript configuration (if using TS)
      • README.md - Usage instructions and examples
    • Basic error handling
    • Example output showing successful operations
    • Support for both CommonJS and ES modules (optional)

The solution should:

  • Use Node.js 18+ or modern browser with fetch support
  • Minimize dependencies (prefer native fetch, optionally add axios if needed)
  • Follow JavaScript/TypeScript best practices and conventions
  • Include clear comments and JSDoc/TSDoc
  • Handle 64-bit integer IDs properly (memory_id as string to avoid precision loss)
  • Support both JSON request/response handling
  • Include example usage in README
  • Work in both Node.js and browser environments (if possible)

Describe alternatives you've considered

  • Using a full-featured HTTP client library - but we want to keep it simple and demonstrate core concepts
  • Creating a complete SDK - but that's too complex for a 2-hour coding session

Additional context

  • The PowerMem HTTP API Server is already available and documented at docs/api/0005-api_server.md
  • Base URL: http://localhost:8000/api/v1
  • API Key authentication via X-API-Key header
  • All endpoints return JSON responses
  • Memory IDs are 64-bit integers that should be handled as strings in JSON to avoid precision loss (see docs/guides/1000-other_notes.md)
  • The example should demonstrate async/await patterns

Metadata

Metadata

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions