postgrest README

The project's README from github.com/PostgREST/postgrest. As one markdown file: README.md.

Logo

Donate Docs Docker Stars Build Status Coverage Status Hackage docs

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch.

Sponsors

Big thanks to our sponsors! You can join them by supporting PostgREST on Patreon.

Usage

  1. See the docs for how to install PostgREST on your platform. You can also use Docker.

  2. Invoke for help:

    postgrest --help
    

Documentation

Latest documentation is at postgrest.org. You can contribute to the docs in PostgREST/postgrest/docs.

Performance

TLDR; subsecond response times for up to 2000 requests/sec on Heroku free tier. If you're used to servers written in interpreted languages, prepare to be pleasantly surprised by PostgREST performance.

Three factors contribute to the speed. First the server is written in Haskell using the Warp HTTP server (aka a compiled language with lightweight threads). Next it delegates as much calculation as possible to the database including

Finally it uses the database efficiently with the Hasql library by

Security

PostgREST handles authentication (via JSON Web Tokens) and delegates authorization to the role information defined in the database. This ensures there is a single declarative source of truth for security. When dealing with the database the server assumes the identity of the currently authenticated user, and for the duration of the connection cannot do anything the user themselves couldn't. Other forms of authentication can be built on top of the JWT primitive. See the docs for more information.

Versioning

A robust long-lived API needs the freedom to exist in multiple versions. PostgREST does versioning through database schemas. This allows you to expose tables and views without making the app brittle. Underlying tables can be superseded and hidden behind public facing views.

Self-documentation

PostgREST uses the OpenAPI standard to generate up-to-date documentation for APIs. You can use a tool like Swagger-UI to render interactive documentation for demo requests against the live API server.

This project uses HTTP to communicate other metadata as well. For instance the number of rows returned by an endpoint is reported by - and limited with - range headers. More about that.

Data Integrity

Rather than relying on an Object Relational Mapper and custom imperative coding, this system requires you to put declarative constraints directly into your database. Hence no application can corrupt your data (including your API server).

The PostgREST exposes HTTP interface with safeguards to prevent surprises, such as enforcing idempotent PUT requests.

See examples of PostgreSQL constraints and the API guide.

Supporting development

You can help PostgREST ongoing maintenance and development by making a regular donation through Patreon https://www.patreon.com/postgrest

Every donation will be spent on making PostgREST better for the whole community.

Contributing

Contributions are always welcome and appreciated. Please see the Contributing guidelines.

Thanks

The PostgREST organization is grateful to:

The cool logo came from Mikey Casalaina.

postgrest (PostgREST/postgrest)

Searching Database…

27.7K ·GitHub
这是什么?PostgREST 是一个独立的服务器,能自动把你现有的 PostgreSQL 数据库变成一套完整的 RESTful API——完全不用写后端代码。
它是我用来做开发的框架,还是我自己运行的服务器?是你自己运行的服务器:一个编译好的独立服务,架在 Postgres 前面,通过 HTTP 把你的表和视图暴露出来,完全不改动你的应用代码。
我怎么把它跑起来?按照文档为你的平台安装 PostgREST 二进制文件,或者直接用 Docker,然后把它指向你的 PostgreSQL 数据库。
客户端会不会通过 API 破坏我的数据?不会——PostgREST 依靠数据库的声明式约束而不是 ORM,所以任何应用(包括 API 服务器本身)都无法破坏你的数据;PUT 请求在设计上就是幂等的。
为什么它比手写的 API 服务器更快?README 里给出了三个原因:编译好的 Haskell 跑在支持轻量级线程的 Warp HTTP 服务器上;把尽可能多的计算交给 Postgres 处理(JSON 序列化、验证、授权和行数统计都在 SQL 里完成);并通过 Hasql 高效使用数据库——这是建立在二进制协议之上的连接池。
分页是怎么实现的?通过普通的 HTTP range 请求头:接口返回的行数既用 range 请求头来上报,也用它来限制,不涉及任何自定义的响应包装结构。
它是免费的吗?是的——PostgREST 是基于 MIT 许可证的开源软件,后续开发由社区通过 Patreon 的捐赠来支持。
Creator
PostgREST
Size
18.2 MB
Stars
27.7K
Age
12y
Commits · 90 Days