What is an API?
An API is an Application Program Interface.
While APIs are widely used in web applications and websites I do not think that they are well explained
There are many places on the Internet that are more than happy to either tell you what their API does or how they can help you use an API and to build an application or website that uses data from an API, but that in itself doesn't really help.
I was aware of the Google Maps API and there are many websites that use this API to extract data from their maps and the Google infrastructure in general. This is an exmaple of what I mean in that Google are more than willing to tell you how to use the API but the internals of the API are propriety to them.
A simple API, like the Fetch API, retrieves text from a file on the server. More conplex APIs could retieve data from more complex repositories such as an SQL database. At first thought this would be a far safer way of doing so than submitting an SQL query using a PHP Data Object.
When using PHP on the client-side the database credentials are most likely exposed to a hacker that works out a way of looking at your source code.