What is an API and how does it work?