Interactive API documentation with Swagger UI. The API can be used from both browsers and command-line tools.
For browser-based applications, you can use the simpler X-User-Pubkey header method:
// Get user's pubkey (hex format) from NIP-07 extension
const userPubkey = await window.nostr.getPublicKey();
// Convert npub to hex if needed
const userPubkeyHex = /* convert npub to hex */;
// Make API request
const response = await fetch('/api/repos/list', {
headers: {
'X-User-Pubkey': userPubkeyHex
}
});
const data = await response.json();For external clients, command-line tools, or cross-origin requests, use NIP-98 HTTP authentication:
// Create NIP-98 auth event
import { finalizeEvent } from 'nostr-tools';
const authEvent = finalizeEvent({
kind: 27235, // NIP-98 auth kind
created_at: Math.floor(Date.now() / 1000),
tags: [
['u', 'https://gitrepublic.com/api/repos/list'],
['method', 'GET']
],
content: ''
}, privateKey);
// Encode to base64
const base64Event = btoa(JSON.stringify(authEvent));
// Make API request
const response = await fetch('https://gitrepublic.com/api/repos/list', {
headers: {
'Authorization': `Nostr ${base64Event}`
}
});Note: The Swagger UI below uses NIP-98 authentication. For browser usage, you can also use the simpler X-User-Pubkey header method shown above.