-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
feat: API routes that return only the data specified #757
Comments
Thinking about this: I think it's a great idea, and I'm wondering what a good API for it would be. <ApiRoute
path="/rss.xml"
response=|cx| {
// so far, so good, right?
}
/> What's the type of pub fn ApiRoute<P, R, Fut>(
cx: Scope,
path: P,
response: R
) -> impl IntoView
where
P: std::fmt::Display,
R: Fn(Scope) -> Fut,
Fut: Future<Output = ???>
{} So that API route response functions can be Ooh or maybe the |
I like it! I agree taking scope is a good thing. I'm not sure which things impl IntoView, but I think that's workable. Actually maybe the return type of response would best be derived from either Axum or Actix? For axum, that might be |
So I finally got around to doing some work on this. Initially my idea was to be able to basically use any handler. I've built most of the infrastructure but the problem is that basically the server-only types can't compile to WASM, at least for Actix, so the Another possibility would be to restrict things here such that an "API route" basically means a route that returns data instead of a view: it's some Is the latter useful enough that you'd want it for an RSS feed or something, as opposed to just adding an API route in EDIT: Wait lol "return a type that implements |
It's a tricky thing, for the blog example the idea of Posts, a Post list, and DB fetching are all occurring in Leptos, not in Axum. That's the kind of stuff you might want to return in an RSS feed. So I could either duplicate all that logic above Leptos. Now that I consider it, since we have GET requests for server functions now, perhaps the answer is to open up the response types for them a bit. For RSS feeds, we'd need XML response types. For binary data that we don't want to encode(image payloads and such), perhaps a Bytes one? |
I'm going to declare “mission accomplished” on this one as of #2158: it is possible, for example, to create an RSS feed using a server function with
|
Routes that return only the content returned from the route. Could be an RSS feed or JSON or maybe even something else.
The text was updated successfully, but these errors were encountered: