import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; serve((req) => { return new Response("Hello from Deno!", { status: 200, headers: { "content-type": "text/plain" }, }); });
The Response object is created with a string body "Hello from Deno!", status 200, and header content-type set to text/plain. This means the client receives exactly that text with a success status.
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; serve((req) => { const method = req.method; return new Response(`Method used: ${method}`); });
The Request object has a property `method` that reflects the HTTP method used by the client, such as GET, POST, etc. So if the client sends GET, method will be "GET".
async function handler(req) {
// parse JSON body here
}The Request object in Deno has an async method `.json()` that returns the parsed JSON body. Other options either misuse synchronous parsing or incorrect method calls.
return new Response({ message: "Hi" }, { status: 200 });
The Response constructor expects the body to be a string, stream, or binary data. Passing a plain object causes a runtime TypeError.
async function handler(req) {
// Access query parameters here
}Deno's Request object has a `url` string property. You can create a new URL object from it and then use `searchParams.get()` to access query parameters.
