Home > Software design >  What is the difference between an API and a database?
What is the difference between an API and a database?

Time:06-13

I am creating a website and have managed to understand that the frontend is mainly visuals and UI. When I looked into storing the user data (username, passwords, etc.) for my website I see many people mentioning APIs (such as GraphQL) and databases (such as MySQL). I was wondering what the difference between the two are, and how the frontend, API, and database all work in conjunction.

CodePudding user response:

The database is something which store your data. It can be as simple as a text file, but it's not safe, not fast and not concurrent. So you need something, that do the storage for you. This is the database server. It can be a local one, a file-based one, or can be on an other server or on some cloud (AWS, Google). It can be even embedded in the backend server. There are many types to use, the most common is MySQL. You can manipulate the data with SQL languge on an SQL server, or you can use some language specific ORM library to do the manipulation without knowing SQL.

The API means Application Programming Interface. It's something that describe how can you interact with the application (in your case with the backend server). It describe what endpoints (like /users) can be used and what data can be sent and get from any endpoint (URL) from your server. Many backend uses RESTful API, where you can access the most of your data with a CRUD. CRUD means Create, Read, Update, Delete, each one describe in the API, for example:

Create a user: HTTP POST to /users

Read a user by its Id: HTTP GET to /users/{id}

Update a user by its Id: HTTP PATCH to /users/{id}

Delete a user by its Id: HTTP DELETE to /users/{id}

The API is describe what data and how should be sent and get from an application. It can also describe the ecryption type, the data type (JSON, XML), and so on.

  • Related