mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api.git
synced 2026-09-22 01:01:59 -07:00
REST2NOSTR Examples
This directory contains examples refactored from the nostr-sandbox/ directory to use the REST API instead of WebSocket connections.
Prerequisites
- Install dependencies:
npm install nostr-tools @noble/hashes
- Start the REST2NOSTR proxy server:
npm start
- Set the API_URL environment variable if the server is not running on localhost:3000:
export API_URL=http://localhost:3000
Examples
01-create-account.js
Creates a new Nostr account keypair and publishes profile metadata (kind 0 event).
node examples/01-create-account.js
02-read-posts.js
Reads posts (kind 1 events) from a specific author using GET /req/:subId.
node examples/02-read-posts.js
03-write-post.js
Publishes a text post (kind 1 event) using POST /event.
node examples/03-write-post.js
04-read-alice-posts.js
Reads posts from Alice's account using GET /req/:subId with author filter.
node examples/04-read-alice-posts.js
14-get-follow-list.js
Retrieves a user's follow list (kind 3 event) using GET /req/:subId.
node examples/05-get-follow-list.js
15-update-follow-list.js
Updates a user's follow list (kind 3 event) using POST /event.
node examples/06-update-follow-list.js
17-liking-event.js
Adds a reaction/like to an event (kind 7 event) using POST /event.
node examples/07-liking-event.js
API Endpoints Used
- POST /event: Publish events to the relay
- GET /req/:subId: Stateless query for events (returns immediately)
Differences from WebSocket Examples
- No WebSocket connections: All communication is via HTTP REST API
- Stateless queries: GET /req/:subId returns events immediately rather than streaming
- Event publishing: POST /event returns immediately with acceptance status
- No subscription management: For stateless queries, subscriptions are automatically closed after EOSE
Notes
- These examples use the same private keys as the original sandbox examples for consistency
- The REST API handles WebSocket connections to relays internally
- For real-time streaming, use POST /req/:subId which supports Server-Sent Events (SSE)