Part 8 Application Programming Interface (API) | System Design Tutorials | Part 8 | 2020
This video topic is about Application Programming Interface (API), in it Yogita goes over:
- What is an API?
- Examples and Use Cases
- Types of APIs
- API Standards
APIs are a core part of system design. It is important to understand how they work, what they are used for, and how to design APIs.
What is an API?
Application were discussed in the previous video, see link. The way that one application interacts with another is via code, hence the programmable part. Last but not least, the interface is the defined portal through which one application has entry and exit point for requests or responses.
Applications can run on the same machine, or different machines separated by multiple networks. Each application can be written in a different language. However, through a defined API - the applications can communicate with each other.
Interfaces also add a layer of abstraction, hence one piece of code calling another piece of code does not need (and should not want to) know the internals of the other piece of code. If one application relies on the internal implementation of another application, this tight coupling means that a change in one can (likely will) break the other. By abstracting the interaction via an interface, the applications do not know the internal workings of the other and reduce coupling.
Advantages of an API
- Communication - APIs provide a means for two pieces of code to interact with each other.
- Abstraction - As mentioned above, APIs provide freedom of implementation. The API provider can refactor or change their implementation and as long as the API behaviour is not changed - there is no impact on the client code calling the API.
- Platform Agnostic - The underlying language or platform is not important when two applications communicate over an API.
Examples & Use Cases
Types of APIs include:
- Private API - these are hidden APIs that are not accessible to the public. For example, making a payment will involve calling a private API.
- Public API - these are accessible to all. For example, Google maps API, weather APIs, etc.
- Web API - these are a super-set of private and public APIs.
- SDK / Library APIs - a threading library may offer APIs for: lock, fork, join, release lock, etc.
A good example of API documentation is Stripe API: https://stripe.com/docs/api. Stripe provides "payment infrastructure for the internet".
API Factors
In designing complex systems, APIs play a vital role. They are essential for moving data in and our of an application, interacting with other applications, and providing an abstraction layer for this communication.
Good API design involves:
- API Contracts
- Documentation
- Data Formats
- Security
The contract defines the type of data communicated, the format, and must be agreed by each side. The documentation contains the contract information and often comes with example code to show how best to interact with the service via the APIs. Data format is a critical factor for designing efficient APIs and security is a of huge importance as it provides and entry point to the application. Each API added increases the attack surface for malicious agents to try to exploit the application to their advantage. Invalid input, rate limiting and throttling, etc are important security considerations in designing an API.
API Standards
Examples of API standards include:
- RPC (Remote Procedure Call)
- SOAP (Simple Object Access Protocol)
- REST (RESTful API)
Each has it's own data format, it's Pros and Cons. We'll look in to each of these standards in future blog posts and compare them.
No comments:
Post a Comment