simple api added
This commit is contained in:
		
							parent
							
								
									4840b9599c
								
							
						
					
					
						commit
						4400cbc69e
					
				| 
						 | 
				
			
			@ -1,2 +1,35 @@
 | 
			
		|||
<script>
 | 
			
		||||
    let text = '';
 | 
			
		||||
 | 
			
		||||
    async function createNote() {
 | 
			
		||||
        const response = await fetch('https://api.brz9.dev/notes', {
 | 
			
		||||
            method: 'POST',
 | 
			
		||||
            headers: {
 | 
			
		||||
                'Content-Type': 'application/x-www-form-urlencoded',
 | 
			
		||||
            },
 | 
			
		||||
            body: new URLSearchParams({ text }),
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        if (response.ok) {
 | 
			
		||||
            // The note was successfully created
 | 
			
		||||
            text = '';
 | 
			
		||||
            alert('Note created successfully');
 | 
			
		||||
        } else {
 | 
			
		||||
            // There was an error creating the note
 | 
			
		||||
            alert('Failed to create note');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<h1>Welcome to SvelteKit</h1>
 | 
			
		||||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
 | 
			
		||||
<ul>
 | 
			
		||||
    <li><a href="/about">About</a></li>
 | 
			
		||||
    <li><a href="/login">Login</a></li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
<input bind:value={text} type="text" placeholder="Enter note text" />
 | 
			
		||||
<button on:click={createNote}>Create Note</button>
 | 
			
		||||
		Loading…
	
		Reference in New Issue