0

Api vs database

I’m a little confused as to when you would use an API over a database. Database seems much easier to deal with. I understand that there are some things that need an API but in the course I was taking I was learning about passing simple info like text with Api. But a database would be so much simpler in my opinion. Am I missing something, or was this just being taught as theory for more complex things?

28th Aug 2024, 4:41 PM
Zvi
Zvi - avatar
5 Respostas
+ 2
These two are not comparable apple-to-apple. A database is used for data management, mainly to create, read, update, delete data. An API is a term used to refer a common interface between an outsider and an insider. API's main function is to bridge between a party who needs data and another party who owns the data. It allows data access restriction by means of API key, which differentiates who gets access to what. In simple terms, an API is like a standard operating procedures set upon servants in a drive-through booth. You request what you want, but whether they give it to you, or not, depends on factors... Whether what you requested was available on the menu, and/or whether they were allowed to serve it, in case it was not (custom topping for example). The business owner defines the sets of rules which defines whether an outsider's (read: customer's) request will or will not be responded. A database in above illustration, acts as the storage of goods they offered, often presented to us, in form of a menu.
28th Aug 2024, 6:45 PM
Ipang
+ 2
if you want to have safer database queries, then you will learn more about API, but API is good for more things, not just for database queries
28th Aug 2024, 6:40 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 1
Ipang So if I understand correctly, for myself or for anything that would contain unrestricted access I would prefer database while things that would need discretion would use API. (Besides for the things that would need an API as pointed out by Mihaly Nyilas). Thanks
28th Aug 2024, 10:44 PM
Zvi
Zvi - avatar
+ 1
Ipang I reread your earlier response and now I think what you mean is api refers to the ability to communicate to a different computer that you want to get/post/put/patch/delete info. Database is where this info is. The source that you are communicating with may have their own database where that info is stored. I hope I am closer to the correct understanding😜. I can’t look at your links right now but will do so when I have the chance.
30th Aug 2024, 12:00 PM
Zvi
Zvi - avatar
0
"So if I understand correctly, for myself or for anything that would contain unrestricted access I would prefer database while things that would need discretion would use API" Hi Zvi Sorry for late answer, Access restriction is feasible and doable both on databases (enforced by the DBMS) and APIs (how it is implemented varies by developers I guess). So it was not about access restriction. I hope these pages can help explain, I seem to have failed in my earlier response, thus your further question ;) https://www.sololearn.com/blog/what-is-database/ https://www.postman.com/what-is-an-api/
30th Aug 2024, 7:10 AM
Ipang