Intro to APIs

Key Points

What is an API?
  • An API is a way for two or more computer programs or components to communicate with each other, enabling efficient data exchange and functionality sharing.

  • APIs allow for selective data retrieval from large, dynamic datasets, eliminating the need to download entire datasets for accessing small segments of data, thereby saving time and computational resources.

  • Both library APIs and web APIs share a fundamental principle of abstracting complexity, allowing developers to leverage pre-defined functions or data over the internet

Web APIs
  • Web APIs enable client-server interactions over the internet through a structured exchange of requests and responses, allowing for seamless data retrieval and submission.

  • The Hypertext Transfer Protocol (HTTP) is crucial for Web API operations, outlining how messages are formatted and transmitted, ensuring consistent communication across different platforms.

  • In HTTP, the communication involves requests initiated by clients (with methods like GET, POST) and responses from servers, each containing headers and potentially a body with the relevant data.

  • HTTPS adds a layer of encryption to HTTP, enhancing security by protecting data in transit, making it essential for sensitive transactions.

Data on the Web
  • How to read structured data types: JSON & XML

  • What are parameters?

  • What are appropriate uses of data retrieved via API?

Creating URL Queries
  • Authentication ensures that only authorised entities can access the API.

  • Authorisation ensures they can only access what they’re permitted to.

  • REST APIs use query stings to make requests

API queries in python
  • The requests and json libraries in Python are important tools to make API calls.

  • Environmental variables are a secure way to store and access API keys from.

  • Some services offer a demo key for testing with limited functionality.

API Queries in Shell
  • You can request and process data from APIs using Unix shell tools

  • JSON or XML results can be parsed to plain text, to be consumed by standard Unix shell tools

Exercise: NCBI E-utilities
  • By linking to the NCBI Entrez system through the E-utilities, you can make complicated data requests across a huge dataset.

Swagger Specification
  • Swagger standardizes API documentation and provides interactive tools for exploring and testing API endpoints.