When i look at magento 2 core, in some modules API directory is present and in some modules there is no API directory.
API Directory is used for implementing Web services(SOAP,REST) or it has other purpose too??
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
Api directory have repositories.
It Contains set of code that third-party developers can call, implement, or build as a plug-in. Magento guarantees that this code will not change in subsequent releases without a major version change.
Public interfaces for a module are marked with @api annotation.
In general, the purpose of a repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory, in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
Magento 2 repository methods can easily be exposed as API resources, making them valuable for integrations with third party systems or headless Magento instances.