Skip to main content

External Functions

Convex actions are the simplest way to interact with the world beyond the database but they can't currently be used to build HTTP APIs. Instead we recommend building your public HTTP API on top of the serverless functions from a hosting provider like Netlify or Vercel.

The steps below include information for both Netlify and Vercel, but should be applicable to any hosting provider supporting functions.

Local environment

Both Netlify and Vercel support local development environments for testing out your local functions. As a first step, let's set up the local environment:

npm install -g netlify-cli

We'll assume you're already running npx convex dev. Ordinarily if you wanted to run the web client locally you'd run npm run dev but now you can run the client within a simulated hosted environment instead by running:

netlify dev

You can fire up netlify dev or vercel dev alongside npx convex dev.

Writing functions

See S3 photo upload demo for examples of the code in api/ directory that defines externally hosted API endpoints.

Deployment

If you followed the tutorial on hosting and deployment then deployment is as simple as committing your changes to your repository and running a git push! Netlify and Vercel automatically watch your repository for changes and publish these to your production site.