CodShot
JavaScript Public

Fetch POST JSON Request

Send JSON data to a backend endpoint with fetch.

#api #javascript #post #json
JavaScript
async function createNote(note) {
    const response = await fetch('/api/notes', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(note)
    });

    if (!response.ok) {
        throw new Error('Could not create note.');
    }

    return await response.json();
}

Notes

Always set Content-Type when sending JSON.

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