I’m a huge PostgreSQL fun and when I saw post about MySQL HTTP API I was very impressed. So, I decided to find something similar for PostgreSQL and it’s here. At the post buttom I find link to PostgresREST. Let’s play with it.
Some words about postgrest. From github page you can see, that it’s fully written in Haskell and uses Warp server which is one of the most powerfull web-servers. More, Warp compiles all sources into single executable file (now, you wiln’t so impressed by content of postgrest archive).
Installation
To install postgrest you need to download curresponding version from github page (current version here) and simply extract it from package. As I said before, Warp compiles all files into single executable file, so, you need just to start it.
Let’s start postgrest server
Prepare PostgreSQL
We are starting from creating simple table named beer using PostgreSQL client:
Let’s see what PostgreSQL generated for us
Playing with postgrest
Let’s make simple request for recrods list
Ok, what about WHERE queries?
It works fine:
Hm, what about INSERT queries?
Let’s see result of it. postgrest supports some kind of pagination with using Range headers (some words about it). Is it interesting? Yes. Is it conventional? Hm, not for me
How you can use it? As example, for this. It provides AngularJS admin GUI to any RESTful API. In our case – for PostgreSQL. You can see how it works here (source here).
postgrest uses a little strange API that can’t be used out of box with any existing libraries for it (such ruby her or activesupport). You need to write your wrapper and it will increase development time. From the another side there is no any need in such libraries for backend languages, we just need JS version. As we can see from ng-admin-postgrest source code, postgrest can be used with Restangular but there is no separated ready-to-use library.
Conclusion
postgrest is interesting tool for providing PostgreSQL REST API. It seems cool for some simple applications. With PostgreSQL views and materialized views it provides a wide range of possibilities but still experimental.
P.S. It’s interesting tendention with backend’s thinning and using frameworks such as Angular or Ember. Will it replace some part of simple rails apps? Time will tell.