CSS Computer Science (Optional) — Paper-I, Section-A, Topic I, p.40. Covers: Application Program Interface (API).
Definition
An API is a defined set of rules, protocols, and tools that allows one piece of software to communicate with another — it specifies how software components should interact, without exposing the internal implementation details of either side.
Key Characteristics
- Acts as a contract: defines what requests can be made, what data format to use, and what responses to expect
- Abstraction: the calling program doesn't need to know how the API's underlying function works internally — only what it does and how to call it
- Enables modularity and reuse: developers can build on existing services (e.g., a weather API) instead of building that functionality from scratch
Common Types of APIs
- Web APIs: accessed over the Internet using HTTP, typically returning data in JSON or XML.
- How it works: a client sends an HTTP request to a server's API endpoint (a URL); the server processes it and sends back a structured response.
- Examples: a weather-service API returning forecast data, a payment-gateway API processing a transaction.
- Advantage/disadvantage: lets independently built systems exchange data over standard web protocols with no shared codebase; performance depends on network conditions and the API depends on the provider staying available/unchanged.
- Operating System APIs: allow applications to request services directly from the OS.
- How it works: exposes system calls/functions for tasks such as file access, memory allocation, process management, and display rendering — an application calls the API instead of manipulating hardware directly.
- Examples: the Windows API (Win32), POSIX API on Unix/Linux systems.
- Advantage/disadvantage: gives applications safe, consistent access to hardware/OS resources without needing to know low-level hardware details; ties the application to that OS's specific API, which is why cross-platform software needs OS-specific handling or an abstraction layer.
- Library/Framework APIs: the set of functions/classes a programming library or framework exposes for other code to use.
- How it works: a developer calls pre-written functions (e.g., a drawing function in a graphics library) instead of writing that functionality from scratch; the library handles the implementation internally.
- Examples: a graphics library's drawing functions, a math library's statistical functions.
- Advantage/disadvantage: saves development time and leverages tested, optimized code; introduces a dependency on that library's version and continued support.
- REST API: a widely used web API design style based on standard HTTP methods operating on resources identified by URLs.
- How it works: resources (e.g., a user record, a product) are addressed by URL, and standard HTTP methods act on them — GET (retrieve), POST (create), PUT (update/replace), DELETE (remove); each request is stateless, carrying all information needed to process it.
- Examples: most modern social-media, e-commerce, and cloud-service APIs are REST-based.
- Advantage/disadvantage: simple, stateless, and scalable, making it the dominant style for web services; being stateless means the client must resend context (e.g., authentication tokens) with every request.
Why APIs Matter (Exam Angle)
- APIs let independently developed software systems interoperate without either needing to know the other's internal source code
- They are central to modern software architecture — mobile apps, websites, and cloud services are largely built by combining calls to multiple APIs
- A good API design principle: expose only what's necessary, hide internal complexity (information hiding — the same principle as encapsulation in OOP)
MCQ Traps
- An API is not software itself — it's a specification/interface for software to communicate; don't confuse it with an application.
- A REST API operates over HTTP using standard methods (GET/POST/PUT/DELETE) — a commonly tested detail.