API – Application Programming Interface, is a set of rules, protocols, and tools that allows different software applications to communication with each other. it defines the methods and data formats that applications can use to request and exchange information.
The Key aspect of an API is Communication. APIs define how different software components interact. They enable applications to access the functionality or data of another service, application, or platform.
TYPES OF APIs
RESTFUL APIs: Principles of Representational State Transfer (REST) and use HTTP requests (GET, POST, PUT, DELETE) to perform actions.
SOAP APIs: Use Xml as a format for exchanging structured information over a network, often using HTTP or other transport protocols.
GraphQL APIs: This allows clients to request only the data they need providing more flexibility compared to traditional REST APIs.
Third-Party APIs: Offered by external services to allow developers access their functionality or data.
USAGE
Development: APIs are crucial in software development, enabling developers to integrate services, access data and create new functionalities.
Integration: They facilitate the integration of different systems, databases and services, allowing them to work together seamlessly.
Authentication and Security: APIs often require authentication (API Keys, tokens, OAuth) to control access to data and functionalities, ensuring security and privacy.
Data Formats: Commonly used formats include JSON (JavaScript Object Notation) and XML for data Interchange.
End Points: APIs have specific endpoints (URLs) that applications access retrieve or send data. Each endpoint corresponds to be a specific functionality or resource.
I will be utilising a Third Party API called Fake Store API.
There are several methods to fetch or retrieve data from an API.
- Fetch API (Native JavaScript): The fetch API provides a simple interface for fetching resources asynchronously across the network. it’s built into web browsers.
- Axios: Axios is the popular third-party library that simplifies making HTTP requests.
- XMLHttpRequest (XHR): This is an older method but it is still used in some scenarios.
- JQUERY AJAX: Jquery Ajax method is often used in legacy codebases.
- Async/Await (For Fetch and Axios): Utilise async and awaitfor cleaner asynchronous code when working with these methods .
Each method has its advantages and may be suitable for specific use cases. I will be utilising the Fetch API method for this tutorial.