TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PostgREST – REST API from any PostgreSQL database

486 pointsby cdjkalmost 10 years ago

26 comments

pilifalmost 10 years ago
Contrary to many other &quot;expose a RDBMS schema as an API&quot; solutions, this one is interesting due to its very close tie-in with postgres. It even uses postgres users for authorization and it relies on the postgres stats collector for caching headers.<p>I also very much liked the idea of using `Range` headers for pagination (which should be out-of-band but rarely is).<p>I&#x27;m not convinced that this is the future of web development, but it&#x27;s a nice refreshing view that contains a few very practical ideas.<p>Even if you don&#x27;t care about this at all, spend the 12 minutes to watch the introductory presentation.
评论 #9930681 未加载
评论 #9930369 未加载
benkantalmost 10 years ago
This is good work and if I ever did web development, it would be like this. Why people in the web world don&#x27;t use stored procedures and constraints is a mystery to me. That this approach is seen as novel is in itself fascinating.<p>It&#x27;s like all those web framework inventors didn&#x27;t read past chapter 2 of their database manuals. So they wrote a whole pile of code that forces you to add semantics in another language elsewhere in your code in a language that makes impedance stark. PostgreSQL is advanced technology. Whatever you might consider doing in your CRUD software, PostgreSQL has a neat solution. You can extend SQL, add new types, use PL&#x2F;SQL in a bunch of different languages, background workers, triggers, constraints, permissions. Obviously there are limits but you don&#x27;t reinvent web servers because Apache doesn&#x27;t transcode video on the fly. Well, you do if you&#x27;re whoever makes Rubby on Rails.<p>The argument that you don&#x27;t want to write any code that locks you to a database is some stunning lack of awareness, as you decide to lock yourself into the tsunami of unpredictability that is web frameworks to ward off the evil of being locked into a 20 year database product built on some pretty sound theoretical foundations.<p>Web developers really took the whole &quot;let&#x27;s make more work for ourselves&quot; idea and ran with it all the way to the bank.<p>You&#x27;d have to pay me a million dollars a year to do web development.
评论 #9928787 未加载
评论 #9928688 未加载
评论 #9928625 未加载
评论 #9928764 未加载
评论 #9928358 未加载
评论 #9928945 未加载
评论 #9930340 未加载
评论 #9929461 未加载
评论 #9928471 未加载
评论 #9929536 未加载
评论 #9929313 未加载
jisteralmost 10 years ago
I&#x27;m sorry but why would I go through HTTP to query data? Why can&#x27;t I just hit the database directly without the overhead of HTTP? Does a cleaner and being more standards-compliant worth the overhead of passing through HTTP?<p>And what happens when you start applying complex business rules that needs to scale? So many questions about this approach...
评论 #9928638 未加载
评论 #9929602 未加载
评论 #9928531 未加载
CloudLeaperalmost 10 years ago
What is the use case of wrapping Postgres with REST? I can&#x27;t think of many apps that don&#x27;t require custom logic between receiving an API request and persisting something to the database. Is PostgREST trying to replace ORM by wrapping Postgres in REST? Or am I missing something. When would one use this tool. My naive perspective needs some enlightening.
评论 #9928548 未加载
评论 #9928472 未加载
评论 #9928432 未加载
评论 #9928419 未加载
weitzjalmost 10 years ago
Could maybe somebody of the older experienced people comment whether this is a good idea?<p>I find it intriguing, but maybe I am just one generation behind and you were to say:<p>&quot;Been there done that. This strong dependency on the database was really not a good idea in the long run because... &quot;
评论 #9928549 未加载
评论 #9928510 未加载
xdangeralmost 10 years ago
How about <a href="http:&#x2F;&#x2F;pgre.st&#x2F;" rel="nofollow">http:&#x2F;&#x2F;pgre.st&#x2F;</a> ?<p>it does same kinda stuff + capable of loading Node.js modules, compatible with MongoLab&#x27;s REST API and Firebase&#x27;s real-time API
bnialmost 10 years ago
What about when changes are made to the schema, wont the API just be changed in that case?<p>Wont this lock you in with very hard coupling between your db schema and public REST API?
评论 #9928811 未加载
评论 #9928739 未加载
CookWithMealmost 10 years ago
Looks really cool. I was first thinking it saves the JSON with the new Postgres JSON support, but saving it as relational data is even more impressive!<p>I&#x27;d say if the OPTIONS would return a JSON Schema (+ RAML&#x2F;Swagger) instead of the json-fied DDL, it would be even more awesome. With a bit of code generation this would be super-quick to integrate in the frontend then.
arturventuraalmost 10 years ago
&quot;It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch.&quot;<p>If you are using this as a web server persistence backend, I would agree with the first, more or less accept the second and reject the third. HTTP + JSON serialisation are way slower for that kind of job.<p>If you are just exposing the database using only the Postgres, in that case is interesting, however, I have concerns about how more complex business logics would work with such a CRUD view.
评论 #9930741 未加载
caseysoftwarealmost 10 years ago
APIs require more than database access, security, and nice routes. Those are all necessary but a good API also includes flows linking things together so you can progress through higher order processes and workflows. You need to make sure that you&#x27;re actually providing user value.<p>CRUD over HTTP (or an &quot;access API&quot;) should be a first step, not your end goal.
评论 #9929320 未加载
gizmodo59almost 10 years ago
With Data Virtualization providers like Denodo you can create a REST web service with any relational database very easily..<p><a href="https:&#x2F;&#x2F;community.denodo.com&#x2F;tutorials&#x2F;browse&#x2F;dataservices&#x2F;2rest" rel="nofollow">https:&#x2F;&#x2F;community.denodo.com&#x2F;tutorials&#x2F;browse&#x2F;dataservices&#x2F;2...</a>
评论 #9928730 未加载
McElroyalmost 10 years ago
Between this (yes, I know it&#x27;s 3rd party) and the support for JSON, PostgreSQL seems to be eating into the market of the NoSQL databases every day. I like that. I like that because the fewer new things I must learn, the more time I can spend on the things I find interesting.
评论 #9934353 未加载
why-elalmost 10 years ago
Splendid work, truly. The documentation is pure class and the whole library is extremely well prepared for actual use. Kudos to the developer.
marknadalalmost 10 years ago
Wow, there is a lot of contention in this thread. So first off I want to say congratulations to the author of PostgREST. Getting 2k req&#x2F;s out of a Heroku free tier is just awesome ontop of all the overhead convenience you provide. Great job, great documentation, all around looking fantastic. You deserve to be on HN homepage.<p>Second, I&#x27;m an author of a distributed database (VC backed, open-source), so I&#x27;d like to respond to some of opinions on databases voiced in this thread - particularly in the branched discussions. If you aren&#x27;t interested in those responses, you can ignore the rest of my comment.<p>- &quot;You&#x27;d have to pay me a million dollars a year to do web development.&quot; Don&#x27;t worry, most webdev jobs are about a tenth of that. If inflation goes up even a little bit...<p>- &quot;The problem is scaling your database&quot;, I can confirm that this is my experience as well. But there is a very specific reason for that. Most databases are designed to be Strongly Consistent (of the CAP Theorem) and thus use Master-Slave architecture. This ultimately requires having a centralized server to handle all your writes, and this becomes extraordinarily prone to failure. To solve this, I looked into Master-Master (or Peer-to-Peer &#x2F; Decentralized) algorithms for my <a href="http:&#x2F;&#x2F;gunDB.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;gunDB.io&#x2F;</a> database. Point being, I&#x27;m siding with @3pt14159 in this thread.<p>- &quot;Sorry but databases are just a hole to put your shit in when you want it out of memory&quot;, I write a database and... uh, I unfortunately kind of have to agree, probably at the cost of making fun of my own product. You see, the reason why is because most databases now a days are doing the same thing - they keep the active data set in memory and then have some fancy flush mechanism to a journal on disk and then do some cleanup&#x2F;compression&#x2F;reorganizing of the disk snapshot with some cool Fractal Tree or whatever. But it does not matter how well you optimize your Big O queries... if the data isn&#x27;t in memory, it is going to be slow (to see why, zoom in on this photo <a href="http:&#x2F;&#x2F;i.imgur.com&#x2F;X1Hi1.gif" rel="nofollow">http:&#x2F;&#x2F;i.imgur.com&#x2F;X1Hi1.gif</a> ). You just can&#x27;t get the performance (or scale) without preloading things into RAM, so if your database doesn&#x27;t do that... well what @batou said.<p>Overall, I urge you to listen to @3pt14159 and @batou. PostgreSQL is undeniably awesome, but please don&#x27;t fanboy yourself into ignorance. Machines and systems have their limitations, and you can&#x27;t get around them by throwing more black boxes at it - your app will still break and so will your fanboyness.
rcarmoalmost 10 years ago
Haskell, huh? The Force is strong on this one.
restyaalmost 10 years ago
Our Restya stack (open source) is similar to this with tech agnostic approach. We used it to build Restyaboard <a href="http:&#x2F;&#x2F;restya.com&#x2F;board&#x2F;" rel="nofollow">http:&#x2F;&#x2F;restya.com&#x2F;board&#x2F;</a> (open source trello alternative&#x2F;clone)
arianvanpalmost 10 years ago
I see currently only &quot;flat&quot; urls are supported. are there any plans (and is it even possible in postgresql) to add dynamic views? so that `&#x2F;users&#x2F;1&#x2F;projects` is a dynamic view, dependent on the $user_id ? . That&#x27;d be rad
spacemanmattalmost 10 years ago
Since I&#x27;ll have to front this with nginx anyway, I may as well use OpenRESTy. I happen to like its REST setup pattern quite a bit.
jawralmost 10 years ago
I wonder if this could easily be forked to provide a GraphQL interface to pg.
dylanvaladealmost 10 years ago
After visiting the demo my browser is running spyware.
hliyanalmost 10 years ago
Is the JSON JSON API [1] compliant, perchance?<p>[1]: <a href="http:&#x2F;&#x2F;jsonapi.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;jsonapi.org&#x2F;</a>
评论 #9928186 未加载
_lce0almost 10 years ago
oh I love the silence logo!!<p>In fact, I think I love any musical reference in software :-)
curiousjorgealmost 10 years ago
The comments are unbelievably negative considering the quality and the range of features this offers. This is extremely useful because I won&#x27;t have to spend time writing out REST api in order to expose the Postgre data. Often a client just wants to access the data with REST api and to write an entire stack just to serve a few doesn&#x27;t make sense. There&#x27;s no expectation that this is going to serve a gazillion requests per minute out of the box, and that&#x27;s totally fine with me since you shouldn&#x27;t rely on off the shelf solutions anyways if you were building an architecture of that size, but really question if you are going to have that many requests per second. It reminds me of the customer who claims &#x27;I need this done in node.js to support 10,000 concurrent users&#x27; and when asked how many users he has now he replies &#x27;none, but I hope I can reach the number&#x27;, solving problems he doesn&#x27;t have yet and complaining that &#x27;php is too slow&#x27;.<p>Some of the best ideas and tools on HN are met with so much negativity it reminds me of Reddit, where the small percentage of people who get off on putting others down so they can feel good about themselves dominate the comments.<p>Good on you cdjk, this is exactly what I was looking for. Thank you!
评论 #9930761 未加载
评论 #9931241 未加载
评论 #9931118 未加载
ficaalmost 10 years ago
Would be cool to put Kong [1] on top of the API to handle JWT or CORS [2] out of the box.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;mashape&#x2F;kong" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mashape&#x2F;kong</a><p>[2] <a href="http:&#x2F;&#x2F;getkong.org&#x2F;plugins&#x2F;" rel="nofollow">http:&#x2F;&#x2F;getkong.org&#x2F;plugins&#x2F;</a>
评论 #9928762 未加载
评论 #9928953 未加载
评论 #9929002 未加载
sz4kertoalmost 10 years ago
You should be aware that this is a _bad_ pattern for anything more serious than a university homework. Instead of exposing functionality that you can guarantee and that&#x27;s required by the clients, you expose your database schema, essentially tightly coupling the DB with the clients.<p>I know it&#x27;s tempting to do that, but spend some time thinking of your data and what do you want to expose.
评论 #9928450 未加载
评论 #9928825 未加载
评论 #9928463 未加载
wistyalmost 10 years ago
Example is broken. It&#x27;s returning a JSON doc, so if you leave it then return, some browsers will just return the cached JSON (as text).<p>Should add some header to say that it&#x27;s JSON, or add a .json file extension for the main page data.<p>Very interesting project though.
评论 #9928171 未加载