If you are working in software or IT industries, this is one of the word that you may hear alot. Many of you are well aware of what exactly are apis and how to build one. For those who are not aware, In this article i will try to tell you the basics of apis.
What exactly are APIS?
If you define apis by JSON responses and URL resources. You are not completely right. API stands for application programmable interface. What does this means? Lets say you have a software and you want to do something programmatically around this then you can use its api to do so.
So what we understand here is API provide ways to code or program around any software given, that software is providing you apis todo so.
What are the need for APIS?
Lets say you have two programs and they want to interact with each other for data. In this case both programs must give an interface that the other can use to get or manipulate data. Now lets say they are written in different languages then the format in which they transfer data needs to be understandable by both. Here comes the most famous formats JSON and XML.
These two data formats are adopted by all languages and are common standards. Its not that you cannot use any other format. The only thing is that both the programs must know how to use the format. You can simply put the data in files in text format if the other is able to understand.
Suggested books for Python
How modern architectures work around these APIS?
In current days the softwares are such that they serve a specific purpose. For other purpose they use other softwares using their APIS. In this way these small softwares comes together to build a whole systems. This architecture is called by some as micro services. Lets see the case of a website which is a Bank Websites. What components or micro services it can have.
- UI: to which you interact on you computer.
- Backend APIS: it is called by UI to get data.
- AUTH APIS: It is called by backend service to authorize if each request is valid and what access it has.
- Security APIS: There can be apis which are serving for encrypting and decrypting data.
This was a small example, websites can interact of hundreds of micro services to present what you see on screen.
How can I build one?
Building simple Apis is pretty easy you can follow these steps to build one. We will be doing it in python using one.
Install virtualenv by below command
pip install virtualenv
Launch a new env
virtualenv venv source venv/bin/activate
Now install flask
pip install flask
The simplest API you can build using this code below in flask.
#!flask/bin/python from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello World!" if __name__ == '__main__': app.run(debug=True)
Now run this file as below
This will run a simple server on port 5000. You can open http://localhost:5000 and see hello world in browser.
It was a simple api and you can learn more around using this blog here.
So this was a simple introduction of apis and how you can build one. I will be posting more about these things so please subscribe and stay aware. Share to let other people know about this blog if you like it.