Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lirone's avatar

Why using a REST API for fetching data from Database ?

I see a lot of people building a REST API from their own MySQL Database.

I don't understand what is the utility of doing that ?

Is it a good practice to build an API from our own database ? Instead of fetching directly from the database ?

What are the avantages of doing that ?

0 likes
2 replies
bobbybouwmann's avatar

Well, it depends on how you need to access the data. If you only have a Laravel project with controllers and blade files there is no need for a REST-API since you can query the database directly.

If you have a frontend app/website and you need to fetch data then it makes sense to create a REST-API. The API itself is also just controllers that query the database directly.

Also if you need to use the same backend for different frontend systems it makes sense to create one API which you can use to collect the data on a single place

CorvS's avatar

@lirone I think you are confusing something here. It depends on the type of your app, but a REST API only really makes sense, when (the name already says it) you want another application to be able to communicate with your app, like a mobile app for example.

Please or to participate in this conversation.