elysiajs / eden

Fully type-safe Elysia client
MIT License
154 stars 37 forks source link

[Feature Request] Eden with Elysia instance. #47

Closed xantiagoma closed 5 months ago

xantiagoma commented 7 months ago

Hi, love your work on Elysia.

Would be great if Eden be used directly with Elysia instance / instance.handle method? I think I would be useful to have a type-safe client that can be used on the server with RSC, server actions or so.

I imagine something like:

import { edenFetch } from '@elysiajs/eden'
import { App } from './server'

const fetch = edenFetch<App>(App)

export default async function ServerComponent() {
  const response = await fetch('/test/:id', {
    params: {
        id: '1895'
    }
});
  const data = await response.json(); // <—- Type inferred
  return (
      <pre>
        {JSON.stringify(data, null, 2)}
      </pre>
  );
}
timvandam commented 7 months ago

came here to request this, first issue i see is this one :tada: definitely a great feature to have for ssr and the like. aside from App it should also be possible to provide a context object.

this feature would also make it easier to test elysiajs. instead of having to provide app.handle with a Request instance we could simply use eden so we don't have to construct it ourselves

xantiagoma commented 5 months ago

Closed as it seems It was already included in new Treaty v2 https://elysiajs.com/eden/treaty/config.html#elysia-instance