Skip to content

How to get a request query from an api route #662

Closed Answered by lucacasonato
waptik asked this question in Q&A
Discussion options

You must be logged in to vote
// 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 });
	},
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@waptik
Comment options

Answer selected by waptik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants