What is faster performance wise? Creating a REST API and having your web app use the REST API to do all interactions with your database OR querying your database directly (i.e. using whatever typical object your language uses to query a database such as JDBC for Java)?
The way I see it with REST:
- You make an object in your code to call the REST method
- Call http method
- Code inside your REST API queries the database
- Database returns some data
- REST API code packs up the data into Json and sends it to your client
- Client receives Json/XML response
- Map response to an object in your code
On the other hand, querying a database directly:
- You make an object with query string to query the database
- Database returns some data
- Map response to an object in your code
So wouldn't this mean that using a REST API would be slower? Maybe it depends on the type of database (SQL vs NoSQL)?