Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I render a .astro component in my api endpoint? #5134

Closed
sygint opened this issue Oct 18, 2023 · 2 comments
Closed

How can I render a .astro component in my api endpoint? #5134

sygint opened this issue Oct 18, 2023 · 2 comments

Comments

@sygint
Copy link

sygint commented Oct 18, 2023

Astro is so amazing!!!!!

But, I don't see anything in the docs about how to create an endpoint that can send back HTML from a .astro component, this would be amazingly helpful. I went back and watched your demo with The Primeagen hoping it explained how, but I noticed he only handles the simple GET request. How can I handle the other HTTP verbs?

something like this would be awesome...

./src/pages/api/sign-up.ts

import { APIRoute } from "astro";

import SignIn from "../../components/SignIn.astro";

export const POST: APIRoute = async ({ request }) => {
  // const data = await request.json();

  return new Response(<SignIn error="Invalid username or password" />));
}
@florian-lefebvre
Copy link
Member

This is not possible yet but there is an ongoing related rfc withastro/roadmap#721

@delucis
Copy link
Member

delucis commented Oct 24, 2023

Thanks for the issue @sygint — the link @florian-lefebvre shared is probably the best resource here.

Given this issue tracker is for ideas and bugs in the Astro documentation site itself rather than issues with Astro, I'll close this and recommend continuing discussion at the roadmap link.

@delucis delucis closed this as completed Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants