iway1 / trpc-panel

MIT License
684 stars 55 forks source link

Support Rest API? #29

Open matannahmani opened 1 year ago

matannahmani commented 1 year ago

Could be super cool if we can add support for Rest API, this can be game-changing as it eliminates the need for open API docs (internal usage)

iway1 commented 1 year ago

that's a great point and something I've thought about before - in cases where a REST api is necessary you need trpc-openapi which has a lot of dev overhead. A solution that autogenerated an Rest API would could eliminate some of those cases, so devs could avoid those very expensive output schemas. (output schemas are crazyyyy expensive to maintain on larger codebases in my experience).

I don't think we could adhere to open api specs or anything (since we'd just be reinventing trpc-openapi at that point), but I think this is probably within the scope of this project (since the goal of this project more or less is to eliminate the need for the need to have to do output schemas and heavy amounts of required meta information).

Some things to consider with this (no need to respond to these unless you have opinions about them):

Any idea about any other specific requirements you'd need?

matannahmani commented 1 year ago

@iway1 First of all thanks for your fast response, overall what you wrote is in line with my thinking. Other than that

iway1 commented 1 year ago

@matannahmani 🙏 good to know.

I'd agree with your convention, seems straight forward.

One question is handling inputs, I'd assume we'll need to do everything with query params if we want to keep it simple, would that work fine?

And if so, is a hard requirement to have each input property be its own query parameter (versus accepting a single object parameter with the whole input)?

matannahmani commented 1 year ago

@iway1 Good point, I think we can separate it on POST it will be on the body, and on GET it will be on query params. About whether we should separate it into properties or just shove it into one key, it's a bit of a hard take. I think it will be a bit more performant when you shove everything into one key, it will be a bit more complex for clients to reproduce. (because they have to use encodeURIComponent and JSON.stringify) Technically speaking if you look at URLSearchParams we can iterate and get all the keys, then reconstruct them into one object that will be passed down into the Zod. I'm down to create a middleware for express this weekend, that will process a request and then transform it into a TRPC request following the conventions we mentioned above.

One question I have is how should we handle errors (404 / or TRPC-defined ones)