Adding middleware inside Postgres for each API request
This is one of the most unknown and underrated features that Supabase provides. The ability to add an API middleware will allow you to control the actual API request before it hits – for example, by implementing rate limiting. So, at its core, you have fine-grained control over API calls.
This consists of two parts:
- Creating a public RPC function that returns tickets from a specific tenant
- Safeguarding the RPC with PostgREST middleware
Let’s say our ticket system has its own API for external developers to interact with tickets. For example, we want to allow developers to access tickets of a tenant at something like /api/tenant_id/tickets
. Certainly, you can just add Route Handlers in the project and implement such an API with the usual code logic. But you can also use the existing PostgREST service to do that. This means there are no additional roundtrips on your server, and you don’t...