API vs SPI
API is a mean for accessing a provided service/function, SPI is way to inject, extend or alter the behavior.
API stands for Application Programming Interface, and is a mean for accessing a service/function provided by some kind of software or a platform. API is normally target for clients to access a service and its has the following properties:
- API is a programmatic way of accessing a service to achieve a certain behavior or output;
- from API evolution point of view, addition is no problem at all for clients;
- but API’s once utilized by clients it can not (and should not) be altered / deleted unless there are an appropriate communications, since its a complete degradation of the client expectation.
SPI stands for Service Provider Interface, and is way to inject, extend or alter the behavior for software or a platform. SPI is targeted for providers and has the following properties:
- SPI is a way to extend / alter the behavior of a software or a platform (programmable vs. programmatic);
- SPI evolution is different that API evolution, in SPI removal is not an issue;
- addition of SPI interfaces will cause problems and may break existing implementations.
Put differently, the API tells you what a specific class/method does for you and the SPI tells you what you must do to conform. So:
- the API is the description of classes/interfaces/methods/… that you call and use to achieve a goal;
- the SPI is the description of classes/interfaces/methods/… that you extend and implement to achieve a goal.
Usually API and SPI are separate. For example in JDBC the Driver class is part of the SPI: if you simply want to use JDBC, you don’t need to use it directly, but everyone who implements a JDBC driver must implement that class.
Sometimes they overlap, however. The Connection interface is both SPI and API: you use it routinely when you use a JDBC driver and it needs to be implemented by the developer of the JDBC driver.
Resources
Categories & Tags
Share