diff --git a/app/json-placeholder/[id]/route.ts b/app/json-placeholder/[id]/route.ts new file mode 100644 index 0000000..2b4f57f --- /dev/null +++ b/app/json-placeholder/[id]/route.ts @@ -0,0 +1,18 @@ +import { NextRequest, NextResponse } from "next/server"; + +export async function GET( + request: NextRequest, + { params: { id } }: { params: { id: string } }, +) { + if (!id) throw new Error("Where is id..."); + + const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`); + + if (!res.ok) { + return new NextResponse("{}"); + } + + const body = await res.json(); + + return new NextResponse(JSON.stringify(body, null, 2)); +}