4 ms·
I am clearly missing something, but at that point, why not just allow the client (presumably a web app running in a browser in most cases) to just make requests
by sopooneo 6y ago
I am clearly missing something, but at that point, why not just allow the client (presumably a web app running in a browser in most cases) to just make requests via SQL? You would of course want to add authentication/authorization layers. You’re want record and field level restriction. But if the entirety of you data is in an RDMS, why put this “REST” paradigm in the middle? Why not just admit you’re querying a database, and query the database? If the only reason is access control, it seems a simpler solution must be possible.
- piaste 6y agoIt's difficult to grant an untrusted client a level of raw SQL access that won't let them do harm. For example, even without access to any specific table or function, even with rate limits, I can denial-of-service the server by asking it to make a massive recursive pure computation.
- tehlike 6y agographql kind of does that. SQL is very complex, T-SQL is turing complete, meaning you can do lots of damage. you can bring servers to a halt if unchecked. It's pretty hard to restrict what can be done keeping flexibility.
- ruslan_talpa 6y agoThis is the “corect” response to the question above. :)
- xwdv 6y agoMost web applications are basically just interfaces to a database. Why even have “REST” at all?
- jaikant77 6y agoYou got me thinking. GET/PUT/POST is not really needed for a completely server rendered app.
- ntr-- 6y agoI think we will see more of a push towards SSR technologies like LiveView for exactly this reason: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html
- tiew9Vii 6y agoI often thought the same with the use of GraphQL. Instead of building a highly curated API with business logic, optimisations and other general stuff you are building a direct interface around how your data looks in the db, a 1:1 mapping and crud interface. In software we are taught to prefer loose coupling vs tight coupling yet here people are preferring the tight coupling. I’m not a fan of this as the user interface (API) has a tight coupling with how you store your data. Then like you say, why not just speak SQL as you have all the same issues, essentially multiple clients writing to/owning the same tables.
- taffer 6y agoThe PostgREST documentation makes it pretty clear that for decoupling and security reasons the data schema should be separated from the API schema. You should only provide the client with views and functions and keep all data in a separate schema. This also solves the versioning problem, because if your API schema is separate from your data, you can simply drop and re-create the entire schema for deployment without needing migrations.
- dragonwriter 6y ago> I am clearly missing something, but at that point, why not just allow the client (presumably a web app running in a browser in most cases) to just make requests via SQL? Because REST-over-HTTP is low impedance with browser-based web apps, whereas SQL is...not. Plus, with REST, you abstract whether all, some, or none of your data is an RDBMS; the fact that you've implemented something with PostgREST doesn't mean everything related to it and linked from it is implemented the same way.
- CuriouslyC 6y agoPostgres isn't 100% set up to let fully untrusted clients do stuff. For example, right now there is no access control around listen/notify. You'd have to do some baseline query pre-processing to be completely secure, which could be a non-trivial task depending on just what you want to let clients do. I've done it in read-only internal business apps though, it's great.