Skip to content
REST API

数据 REST API

Supabase 会根据你的数据库模式自动生成一个 API,让你可以直接通过浏览器通过 RESTful 接口连接到你的数据库。

🌐 Supabase auto-generates an API directly from your database schema allowing you to connect to your database through a restful interface, directly from the browser.

这个 API 是从你的数据库自动生成的,设计宗旨是让你尽快开始构建应用,而无需写一行代码。

🌐 The API is auto-generated from your database and is designed to get you building as fast as possible, without writing a single line of code.

你可以直接从浏览器使用它们(两层架构),也可以作为你自己 API 服务器的补充使用(三层架构)。

🌐 You can use them directly from the browser (two-tier architecture), or as a complement to your own API server (three-tier architecture).

功能 #

🌐 Features [#rest-api-overview]

Supabase 使用 PostgREST 提供一个 RESTful API,这是一个在 Postgres 之上的轻量级 API 层。它在 https://<project_ref>.supabase.co/rest/v1/ 网址提供了你从 CRUD API 所需的一切。

REST 接口会根据你的数据库模式自动生成,它是:

🌐 The REST interface is automatically reflected from your database's schema and is:

  • 即时且自动生成: 当你更新数据库时,变化会立即通过你的 API 可访问。
  • 自带文档: Supabase 会在仪表盘中生成文档,并会随着你对数据库的更改而更新。
  • 安全: 这个 API 配置为与 Postgres 的行级安全(Row Level Security)一起使用,并且在启用密钥认证的 API 网关后面提供。
  • 快: 我们的基本读取基准比 Firebase 快超过 300%。API 只是位于 Postgres 上的一个很薄的层,Postgres 执行了大部分繁重的工作。
  • 可扩展: 这个API可以处理成千上万的同时请求,并且非常适合无服务器工作负载。

反射 API 的设计目标是尽可能保留 Postgres 的功能,包括:

🌐 The reflected API is designed to retain as much of Postgres' capability as possible including:

  • 基本的 CRUD 操作(创建/读取/更新/删除)
  • 表/视图之间可以有任意深度的关系,返回表类型的函数也可以嵌套相关的表/视图。
  • 适用于 Postgres 视图、物化视图和外部表
  • 支持 Postgres 函数
  • 用户定义的计算列和计算关系
  • Postgres 的安全模型——包括行级安全、角色和权限。

这个 REST API 会把所有请求都转成一条 SQL 语句,从而响应快,吞吐量高。

🌐 The REST API resolves all requests to a single SQL statement leading to fast response times and high throughput.