/restr

Nostr REST API proxy

Primary LanguageTypeScriptMIT LicenseMIT

Restr

Nostr REST API proxy on Cloudflare Workers.

Client implementation is simplified by having proxy server handle communication with relays.
It also reduces the amount of communication on client.

Usage

GET /{nevent}

{nevent} is NIP-19 and requires id and relays.

GET /{naddr}

{naddr} is NIP-19 and requires kind, pubkey, identifier and relays.

GET /{nprofile}

{nprofile} is NIP-19 and requires pubkey and relays.

This is an alias of naddr with kind 0 and empty identifier.

POST /{nevent}

{nevent} is NIP-19 and requires relays.

Request body is event JSON.

POST /req

Fetch events.
POST method is used because filters can be long.

Request body contains relays and filters.

{
  "relays": ["wss://example.com/"],
  "filters": [{ "limit": 10 }]
}

POST /req/stream

This is Server-Sent Events with POST method.
POST method is used because filters can be long.
Use a library which can handle POST method (sse.js, launchdarkly-eventsource, eventsource-client, @microsoft/fetch-event-source, etc.) instead of EventSource.

Request body contains relays and filters.

{
  "relays": ["wss://example.com/"],
  "filters": [{ "limit": 10 }]
}

Development

npm install
npm run dev

Test

cd test/
docker compose up --build -d --wait
npm test
docker compose down --volumes

Deploy

npm run deploy