I am learning about REST APIs, and I don't really understand it's use. I created an API which can do CRUD operations, but I can do the same using simple PHP code. Why does API come into the picture?
Asked
Active
Viewed 373 times
-3
-
what is your attempt? – Hien Nguyen Jun 15 '19 at 06:37
-
I have created an API to do operations like creating, updating, deleting records from the database. But why do this with API and returning json instead of using just php? – John S Jun 15 '19 at 06:39
-
Refer [here](https://stackoverflow.com/questions/7440379/what-exactly-is-the-meaning-of-an-api) – Rasa Mohamed Jun 15 '19 at 06:42
-
2This is a rather broad conceptual question, as such I will have to vote close. Basically a REST-API using JSON is useful when your PHP application wants to communicate (synchronously) with a different application. JSON is the defacto standard, because it is concise, human-readable and easily processable in many languages. – dbrumann Jun 15 '19 at 06:43
1 Answers
0
You don't have to return a JSON, your API can return anything as you want. But, why do you create an API, to expose some data? So, is it not more logic to have a human readable, ready to use and a standard output? That's why every API use JSON or XML as well

JessGabriel
- 1,062
- 9
- 18
-
ok then why do we need an API, the same tasks can be performed by simple PHP code itself – John S Jun 15 '19 at 07:37
-
I think you are confused. PHP is just a language, API is an approach to expose data to another consumer. It doesn't matter if you use PHP or Java or whatever to expose your data. – JessGabriel Jun 15 '19 at 07:41