CodShot
JavaScript Public

Fetch GET Request

Load JSON from an API endpoint with async and await.

#api #javascript #fetch #json
JavaScript
async function searchSnippets(query) {
    const url = `/api/snippets?search=${encodeURIComponent(query)}`;
    const response = await fetch(url);

    if (!response.ok) {
        throw new Error('Search request failed.');
    }

    return await response.json();
}

Notes

Use encodeURIComponent when adding user input to query strings.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support