Skip to main content

Endpoints

Get

src/routes/api/items/[id]/+server.js
// /api/items/1
export async function GET({ params }) {
const id = params.id;

if (id == 1) {
return {
id,
};
}

throw error(404, "Not found");
}

Post

src/routes/api/items/+server.js
export async function POST({ request }) {
const { param1 } = await request.json(); // or .formData(), or .text(), etc

return {
param1,
};
}