How to get a request query from an api route #662
Replies: 1 comment 1 reply
-
// routes/api/wrap.ts
import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
async GET(req, ctx) {
const url = new URL(req.url);
const action = url.searchParams.get("action");
if (!action) return new Response("Bad Request", { status: 400 });
return Response.json({ action });
},
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
waptik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I'm trying to get the query from an api route.
Eg:
http://localhost:8000/api/wrap?action=info
I can't seem to find any object to from
req
orctx
to get theaction
query and it's value.Beta Was this translation helpful? Give feedback.
All reactions