What is API?
Tags: api, webdev, hasanelsherbiny, newbie
Published: 2023-07-28 20:14:08

## API Stands for application programming interface.
so what does that actually means?

in programming there is a great concept "DRY" 
Don't repeat your self which means you don't need to reinvent the wheel every time you want to use it.
so if you have a specific functionality that can be used by another system or application you shouldn't rewrite it again.

## Why?

because this would be a double effort for rewriting and maintaining, also what if this functionality has specific requirements like depending on a particular library which requires custom configuration or setup or requiring specific environment to run and/or needs some resources that you wouldn't be able to allocate if you want to have this functionality on device that doesn't have it.

## So what to do?

to solve the part related to reusability only you can simply wrap your functionality into a library "DLL (Dynamic link library)" and import it in other projects need to have the functionality.
this type is commonly used and you may have used it many times without knowing, also sometimes it's called SDK (Software development kit) "this name mostly used when the functionality related to hardware you want to integrate with".

but this still doesn't solve the other problem of resources allocation and also creates a new problem related to compatibility and usage if the library and the new project using different programming language or different versions of the same language.

so another way to share your functionality is to use "Web API"
in this way your functionality will have web endpoints with clear inputs and output (XML/JSON/plain text) allowing other applications to communicate with it through HTTP Protocol ,the most famous types are(SOAP/Rest). 
in such way you don't have to rewrite your functionality to be used and also your functionality will live on separated server where you can allocate any resources you want without limitations of the consuming project and also the platform or the technology of consuming project so it can be web/desktop/mobile project.
also any decencies required by your functionality will be installed and configured on the server.

another benefit of having API is the data storage what if I'm offering my functionality as a service and this functionality must have access to specific data ?
in this case API is super useful as it's web based as we discussed and your data can be stored on the server besides your API.
and in this case API Can be called API Gateway because obviously it's acting like a gateway for your data, 

## Sounds familiar? 
yes this is the same case you can see when using mobile applications such amazon store, for sure all products are not stored on your mobile and also the application cannot have access to the database directly so it will communicate with the API as mentioned.

## So how can i create an API?
as mentioned before you can simply wrap your code into DLL or build a web API
for web API it's not more than a web endpoint accepting your request and return the data in response so all web development programming languages and framework such as (php-asp.net- ruby on rails) will support building an API.