In this issue of newsletter we will explore the APIs. I will provide an introduction to API. By the end of this article you will be able to understand the following topics:
- What are web APIs?
- What is its use?
- Features of good API?
API stands for application Programming Interface. An API defines a way in which two systems interact with each other. APIs are almost everywhere examples can be Twitter bots, Google Maps, Travel Booking and many more. APIs are special types of interface that defines how two computer systems interact. APIs can be categorized into downloadable APIs and web APIs.
- Web API:A Web API is an API that is accessible over the internet using standard web protocols such as HTTP. It is typically hosted on a server and allows communication between different software applications, either within the same organization or across the internet. Web APIs are commonly used in web development to enable communication between the front-end (client-side) and back-end (server-side) of web applications. RESTful APIs and SOAP (Simple Object Access Protocol) APIs are examples of web APIs. RESTful APIs, in particular, have gained widespread popularity due to their simplicity and scalability. Web APIs have no copies and the source code is not available to the client. That's why if a web API changes those changes are forced on the users/client. The user/client has no control over the web API they use. For example there is an web API that allows to encrypt data. Today the encryption API may use public key encryption tomorrow they may change it to private key encryption and later they decide to shut down this API. So, at this point the client application will suddenly stop working and nothing could be done about it. Probably this is the most important benefit of web API the developers building the API have full control of it.
- Downloadable API:A downloadable API refers to an API or SDK (Software Development Kit) that developers can download and integrate into their local development environment or application. These APIs are often provided by software vendors, service providers, or open-source projects to facilitate the integration of their services or functionalities into custom applications. Downloadable APIs can include libraries, software components, documentation, and tools that developers need to interact with a specific service, hardware device, or software functionality. Examples of downloadable APIs include libraries for accessing database systems, SDKs for integrating with hardware devices, or software packages that provide specific functionalities like image processing or machine learning.
Given below are some common uses of APIs.
- Data Access and Integration: APIs enable applications to access and integrate data from external sources or services. For example, a weather application may use a weather API to retrieve real-time weather data.
- Service Integration: APIs facilitate the integration of various services and applications. For instance, a payment processing service may provide an API that allows e-commerce websites to securely process payments.
- Automation: APIs enable automation by allowing different software components to communicate and perform actions programmatically. This is particularly useful in scenarios where manual intervention is not efficient or practical.
- Third-Party Integrations: Many applications provide APIs to allow third-party developers to extend and enhance their functionality. Social media platforms, for example, often offer APIs that developers can use to integrate social features into their own applications.
- Mobile App Development: APIs are essential in mobile app development, allowing mobile applications to interact with server-side databases, services, and other resources.
- Cloud Computing: Cloud service providers offer APIs to enable users to manage and interact with their cloud resources programmatically. This includes services like storage, computing power, and databases.
- Web Development: APIs are commonly used in web development to enable the interaction between the front-end and back-end of web applications. Web APIs (often RESTful APIs) are used to send and receive data between the client and server.
- IoT (Internet of Things): In IoT applications, APIs play a role in allowing devices to communicate with each other and with cloud-based services. This is crucial for the exchange of data and control commands.
- Machine Learning and AI: APIs are used to integrate machine learning models and AI services into applications, allowing developers to leverage advanced capabilities without having to build these models from scratch.
In summary, APIs serve as bridges between different software systems, allowing them to communicate and share functionality, data, and services. They are fundamental to the modern software development landscape, enabling interoperability and fostering innovation.
- Operational - The API should actually do function as user intends. No matter what the final interface looks like the system as a whole should be operational. If the system intends to translate text from one language to another then it must be able to do so. Apart from this there might be some non operational requirements like latency (time taken to translate the text in 5 milliseconds) or accuracy (e.g. More than 95% accurate). So, these aspects also constitute to the operational aspect of a system.
- Expressive - When we say that an API should be expressive, we mean that it should allow developers to achieve a wide range of functionalities in a clear and intuitive manner. An expressive API refers to how well the API can convey its capabilities, features, and usage patterns to developers. An expressive API is one that is easy to understand, flexible and provides a natural way for developers to interact with it. For example : Suppose there is an API that translates the input text. The design of the API should have a method TranslateText(). It should detect the input text language and then return the translated text otherwise return an error stating that the language of input text is not supported. APIs that are expressive provide the ability for users to clearly dictate exactly what they want (e.g., translate text) and even how they want it done (e.g., “within 150 milliseconds, with 95% accuracy”).
- Simple - The principle that an API should be simple emphasizes the importance of clarity, ease of use, and a straightforward design in the creation of API. While simplicity is essential, it's important to strike a balance. An API should be simple without sacrificing necessary features, flexibility, or the ability to handle diverse use cases. The goal is to make the API as straightforward as possible while still providing the functionality and versatility required by developers. If we take the example of text translation. Suppose in future we have another consumer that needs some advanced functionality to get the model_Id. Because of this we shouldn't break the existing functionality we should use the same translateText(string inputText, string tagetLanguage, string? modelId) and then return the translated text with model_Id if it exists. Defining modelId nullable will solve all the cases.
- Predictable - APIs that rely on repeated, predictable patterns (e.g., naming fields consistently) are easier and faster to learn and therefore better. APIs built using well-known, well-defined, clear, and (hopefully) simple patterns will lead to APIs that are predictable and easy to learn, which should lead to overall better APIs.
APIs are special type of interface to define how two systems interact with each other. Web APIs are special as they expose functionality over a network, hiding the specific implementation or computational requirements needed for that functionality. A good API should be operational, expressive, simple and predictable.