Introducing PostgREST, a REST API for any PostgreSQL database written in Haskell

PostgREST, crafted in Haskell, serves as a standalone web server that seamlessly transforms existing PostgreSQL databases into RESTful APIs. This tool is designed to provide a more refined, standards-compliant, and efficient API compared to what developers might create from scratch. The documentation emphasizes that PostgREST acts as an “alternative to manual CRUD programming,” addressing the common pitfalls of duplicating or misrepresenting database structures in business logic. It champions a philosophy that prioritizes a single declarative source of truth: the data itself.

Performant by design

When it comes to performance, PostgREST excels, showcasing subsecond response times for up to 2000 requests per second, even on the Heroku free tier. This remarkable efficiency is largely attributed to its Haskell foundation, which employs the Warp HTTP server. To sustain rapid response times, PostgREST offloads significant computational tasks to the database, including JSON response serialization and data validation, thereby optimizing performance. Additionally, it leverages the Hasql library for effective database interactions.

A single declarative source of truth for security

In terms of security, PostgREST manages authentication through JSON Web Tokens (JWT), allowing for the development of various authentication methods atop this foundational layer. Authorization is handled via role information defined within the database, reinforcing the concept of a singular declarative source of truth for security measures.

Data integrity

PostgREST distinguishes itself by avoiding reliance on Object Relational Mappers (ORMs) and custom imperative coding. Instead, it encourages developers to implement declarative constraints directly within their databases, effectively safeguarding against data corruption. Feedback from users on platforms like Hacker News has been largely positive, with one user remarking, “I think PostgREST is the first big tool written in Haskell that I’ve used in production. From my experience, it’s flawless. Kudos to the team.” However, some users have raised concerns about the complexities that can arise when deploying this tool in production environments. One user noted, “Somebody in our team put this on production. I guess this solution has some merits if you need something quick, but in the long run it turned out to be painful. It’s basically SQL over REST. Additionally, your DB schema becomes your API schema and that either means you force one for the purposes of the other or you build DB views to fix that.”

For further exploration of PostgREST, you can visit its official website or check out its GitHub repository.

Tech Optimizer
Introducing PostgREST, a REST API for any PostgreSQL database written in Haskell