Back to articles
SvelteKit Has a Free API: Full-Stack JavaScript Without the React Tax

SvelteKit Has a Free API: Full-Stack JavaScript Without the React Tax

via Dev.to WebdevAlex Spinov

React developers spend half their time fighting React. SvelteKit developers spend that time building features. What Is SvelteKit? SvelteKit is the full-stack framework for Svelte — think Next.js but for Svelte. It gives you server-side rendering, API routes, file-based routing, form actions, streaming, and edge deployment. Unlike Next.js, it compiles away the framework. Your users download plain JavaScript, not a runtime. The API Routes SvelteKit's +server.js files are API endpoints: // src/routes/api/users/+server.ts import { json } from ' @sveltejs/kit ' ; export async function GET ({ url }) { const limit = Number ( url . searchParams . get ( ' limit ' ) ?? 10 ); const users = await db . user . findMany ({ take : limit }); return json ( users ); } export async function POST ({ request }) { const { name , email } = await request . json (); const user = await db . user . create ({ data : { name , email } }); return json ( user , { status : 201 }); } Form Actions: The Killer Feature For

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles