Code Examples

Interactive Code Examples

Run live examples to see the OpenNotes API in action. Click "Run" to execute each code snippet.

Get All Notes

Fetch a list of notes with optional sorting and limiting

GET
// Get notes sorted by views
const response = await openNotesAPI.getNotes({
    sort: 'views',
    limit: 5
});

// Display results
response.items.forEach(note => {
    console.log(note.title, '-', note.v, 'views');
});
Click "Run" to see results

Search Notes

Search for notes by keyword with filtering options

GET
// Search for physics notes
const results = await openNotesAPI.searchNotes('physics', {
    format: 'pdf',
    limit: 10
});

console.log('Found', results.items.length, 'notes');

results.items.forEach(note => {
    console.log(`- ${note.title} by ${note.auth}`);
});
Click "Run" to see results

Get Statistics

Retrieve comprehensive statistics about the notes collection

GET
// Get comprehensive statistics
const stats = await openNotesAPI.getStatistics();

console.log('Total Notes:', stats.totalNotes);
console.log('Total Views:', stats.totalViews);
console.log('Total Downloads:', stats.totalDownloads);

console.log('\nFormat Distribution:');
Object.entries(stats.formats).forEach(([fmt, count]) => {
    console.log(`  ${fmt}: ${count} notes`);
});
Click "Run" to see results

Get Notes by Author

Filter notes by a specific author

GET
// Get all notes by Chenyu Li
const authorNotes = await openNotesAPI.getNotesByAuthor(
    'Chenyu Li'
);

console.log('Notes by Chenyu Li:');
authorNotes.items.forEach(note => {
    console.log(`  - ${note.title}`);
    console.log(`    Views: ${note.v}, Downloads: ${note.d}`);
});
Click "Run" to see results

Trending Notes

Get the most viewed notes

GET
// Get top 5 trending notes
const trending = await openNotesAPI.getTrendingNotes(5);

console.log('๐Ÿ”ฅ Trending Notes:\n');

trending.items.forEach((note, i) => {
    console.log(`${i + 1}. ${note.title}`);
    console.log(`   ๐Ÿ‘€ ${note.v} views | ๐Ÿ“ฅ ${note.d} downloads`);
    console.log(`   Author: ${note.auth}\n`);
});
Click "Run" to see results

Full Integration Example

Complete example showing multiple API features together

FULL
async function displayDashboard() {
    // Check API health
    const healthy = await openNotesAPI.healthCheck();
    console.log('API Status:', healthy ? 'โœ… Online' : 'โŒ Offline');
    
    if (!healthy) return;
    
    // Get stats
    const stats = await openNotesAPI.getStatistics();
    
    console.log('\n๐Ÿ“Š Dashboard\n');
    console.log(`Total Notes: ${stats.totalNotes}`);
    console.log(`Total Views: ${stats.totalViews}`);
    
    // Show top note
    if (stats.topViewedNotes[0]) {
        const top = stats.topViewedNotes[0];
        console.log(`\n๐Ÿ† Top Note: "${top.title}"`);
        console.log(`   ${top.v} views, ${top.d} downloads`);
    }
}

displayDashboard();
Click "Run" to see results
widgets

Live Demo: Notes Browser Component

Interactive notes browser with full functionality

search

Live Demo: Search Component

Try the search with autocomplete suggestions