How does an API work and how it can help ports?

How does an API work and how it can help ports?