DEV Community

Discussion on: Why do Webdevs keep trying to kill REST?

Collapse
 
bklau2006 profile image
BK Lau

Have you heard about Database stored procedures?
If not, read on below:

  1. Traditionally, clients would be sending a one or more SQL to database(backend) to query the data they need. A number of times, they just fetch data from server and merge/aggregate the data on the client side. In short the smart logic lies in the clients know what they want and how they want it.
    This is analogous to calling REST API backends.
    However,...
    Client queries are expensive and slow and tedious to do over data that spans several tables with complex joins...and you need to know SQL really well.

  2. This is where database stored procedures comes in.
    You predefined a "function" on the database backend that takes in several parameters. Every programmers knows what a function is.
    This database "function" is called Stored Procedures. Look it up.
    So its like a GraphQL endpoint.
    So you just send query parameters to the backend database instead of sending raw SQL queries. You don't even need to know SQL!
    The data you need from several queries are run and merged by the database stored procedure automatically. Isn't that neat?

I see GraphQL as a reinvention of backend database stored procedure ala web style.