puchesjr
puchesjr•5mo ago

Using Convex to expose an HTTP API

hey, so we are going to go 100% convex for a new service. We do not need a client exposed api yet, but we will in the future. one of the ideas we'd like to see is autogenerated docs "openapi" and validation for api endpoints if we use convex to host our rest api. if hosting the rest api, we would like the ability to add things like rate limits, etc. to prevent bad actors. if this is not the intended direction/use case of convex longterm, would like to understand the best way to consume the convex database from our external rest api - e.g., created in Go. @jamwt @james
11 Replies
RJ
RJ•5mo ago
Hey @puchesjr, this is all quite well-supported by Convex, IMO. You can wire up libraries like Hono (see, for example, this Stack post on the topic) which would then grant you access to middleware for generating OpenAPI specs and live API documentation (e.g. via Scalar. It looks like Hono has rate limiter middleware that you could use as well, or you could use Convex's rate limiter component. I also maintain and use a library (still in alpha) where I use Effect's version of Hono to accomplish the same thing, and I can confirm that the implementation is very straightforward. If you'd like to see a live example of public API documentation rendered like this feel free to DM me and I can send you a link. Either way, main takeaway is this is well within Convex's wheelhouse; if anything it's (IMO) something that Convex handles really well. And folks here can definitely help you get this set up when the time comes, too.
puchesjr
puchesjrOP•5mo ago
This is fantastic to hear, i'll check it out and thank you for the response. I want to see how fast we can go from ground zero to deploy. we start coding tomorrow.
RJ
RJ•5mo ago
Exciting, good luck!
Neco | nokta.dev
Neco | nokta.dev•3mo ago
@RJ justsaw confect looking interesting. planning to maintain it?
RJ
RJ•3mo ago
100% @Neco | nokta.dev, I use it in production myself. I've been working (very slowly, as I've been traveling abroad for basically the last 9 months) towards a 1.0 release as well.
devagr
devagr•2mo ago
Hey! Is there a way to run internal functions using confect? the context object seems to only expose auth, db, and storage, but not a way to run queries and mutations
RJ
RJ•2mo ago
Hey @devagr, if you're trying to run an internal query or mutation from another query or mutation, you shouldn't (generally) be using runQuery or runMutation to do this (see https://docs.convex.dev/understanding/best-practices/#use-ctxrunquery-and-ctxrunmutation-sparingly-in-queries-and-mutations). If you need runQuery or runMutation to use a component (or because you want partial rollbacks), let me know I can look into adding it!
devagr
devagr•2mo ago
thanks for the response! i figured something like that, switched the internal queries to be regular functions instead
RJ
RJ•2mo ago
No problem! If you have any other questions or run into any other issues, feel free to reach out 🙂
devagr
devagr•2mo ago
do you prefer chatting over DMs or another thread?
RJ
RJ•2mo ago
I'm happy to chat over DMs but if it's stuff that might be useful to other people it would probably be nice to discuss in a public thread

Did you find this page helpful?