tRPC alternatives for a simple public API

I have a T3 monorepo with tRPC with 100+ PRIVATE API endpoints. 1) I want to create a public API with around 10 basic read endpoints that can be used across various platforms and languages. What other options do y’all suggest? 2) Is there any way to expose both REST and GraphQL simultaneously?
No description
8 Replies
cadams
cadams9mo ago
Not sure I understand your question 100% but have you heard of trpc-openapi ? https://github.com/jlalmes/trpc-openapi Apparently it can make you use your trpc routes like normal REST endpoints.
GitHub
GitHub - jlalmes/trpc-openapi: OpenAPI support for tRPC 🧩
OpenAPI support for tRPC 🧩. Contribute to jlalmes/trpc-openapi development by creating an account on GitHub.
Endgame1013
Endgame10139mo ago
If you’ve only got 10 read endpoints that you want to expose, then why not just use standard REST endpoints? Regarding exposing GraphQL and REST, The Guild has a pretty neat package called GraphQL SOFA that can expose REST routes from your GraphQL schema (although I think it’s limited to just Express at the moment): https://the-guild.dev/graphql/sofa-api
GraphQL SOFA
Home – GraphQL SOFA
GraphQL SOFA Documentation
teos
teos9mo ago
I'm currently working on a small lib to build REST APIs in a similar way to tRPC. Which is a common use case I think, especially if you use tRPC already. I haven't released it yet, maybe you would be interested in trying it out ?
Endgame1013
Endgame10139mo ago
@teos that sounds dope. Would you be willing to drop a link?
teos
teos9mo ago
Sure, I need to publish it first, I'll post a link to npm here, probably tomorrow
teos
teos9mo ago
npm
@trestjs/react-query
React Query - End-to-end typesafe REST APIs, the tRPC way. Latest version: 0.0.6, last published: 2 minutes ago. Start using @trestjs/react-query in your project by running npm i @trestjs/react-query. There are no other projects in the npm registry using @trestjs/react-query.
teos
teos8mo ago
@Endgame1013 It's still a proof of concept, you're welcome to try it out. It won't replace tRPC anytime soon, but it lets you to define REST routes, and you can control searchParams, body, headers, etc, with full type safety Technically, it could become tRPC compatible, but I'm not focusing on that right now. I just want to build fast AND have a RESTful API to share with other devs/teams (not a custom protocol like tRPC) Let me now what you think, any feedback/help would be greatly appreciated 🤓 @Eddy - SolarX is this the kind of project you're looking for ?
JJ Rise
JJ Rise8mo ago
I had a very similar use case. We have a large private tRPC api for our t3 based monorepo and wanted to expose a handful of public endpoints. I ended up setting up Hono as a package and doing it that way. Could still share my db instance and was pretty smooth for the most part.
Want results from more Discord servers?
Add your server
More Posts
i am building a react component library how can i keep the bundle size very lowI am trying to build a component library for react Nothing to crazy just a simple and sing componentBest way to prefetch queries with tRPC and app/ dirI am in the process of switching my pages/ T3 app to the new fancy app directory and know that ReactonSuccess, onError and onSettled deprecated next major version?with `onSuccess`, `onError` and `onSettled` being deprecated soon™️, what would the best practice beHow did Vercel Implement this ??When you encounter an error, it opens up the editor file in VSCode. How do you built this browser feHave someone implemented pagination with server actions and prisma?Could you send link if soRestrict direct access to NextJS routesI am writing a user onboarding flow where the whole onboarding flow is about 3 pages, it starts withShould I use "use server" directive for database queries```ts "use server" import { db } from "~/server/db"; export async function getArticle(id: string) Is there a way to refactor the query/mutation function to a different file?Basically I'm wondering if it's possible to get the type of the function that's passed into the querI'm a complete React beginner, is this the correct approach for Components?Hello everyone, I am tasked to do some buttons that have both a logo, and text. The logo is supposedHow to keep track of multiple running mutations with same function but different input variables?I have a single mutate function that's basically: const doWork = api.example.doWork.useMutation()