APIs - digitalideation/studio_web1_2024 GitHub Wiki

APIs

API stands for Application Programming Interface. An API is a software interface that is used by other software. In constrast UIs are interfaces that are used by human users. In this module, we are using Web APIs (sometimes also called HTTP APIs or web services) that are accessed by sending and HTTP request to a server. Other types of APIs include software libraries, browser APIs (which are sometimes also called Web APIs) or operating system interfaces.

API specifications

API specifications describe what HTTP requests can be made to an API. They describe which HTTP methods (for example GET, POST) to use and what parameters to set. A good API description also includes the structure of the response and the different types of responses to expect (for example for errors). A widely used standard for writing API specification is OpenAPI. Tools like Swagger can display OpenAPI specification as documentation and let users directly interact with the API.

Swagger example

Postman

Postman is a useful tool for exploring APIs. It allows you to send requests to an API. We will look at the main components of an HTTP request together in Postman. Screenshot of Postman

APIs in this module

Swiss food composition database

This API allows you the search for foods (e.g. cordon bleu), its ingredients (pork, cheese, ham, ...) and various values about the ingredients (e.g. calories, macro- and micronutrients).

For example, we can search for cordon bleu. Cordon bleu query

We can then use the id from the result to search for all ingredients of the pork cordon bleu. Cordon bleu ingredients query

Finally, we can get values (such as calories, protein content) for an ingredient. Pork values

Spotify

You can find the Spotify Web API documentation here. There are two main ways to use the Spotify API.

  • You can access general information about artists, albums, genres, etc. To do this, you can use the getting started guide and a tool like Postman. You can also try out the API directly from the documentation, for example getting information about an album
  • You can access personal information about the logged in user, for example top artists or tracks. You can also try the API directly from the documentation, for example getting user's top items. You can also do this programmatically, following the PKCE Flow tutorial. You can find a reference implementation in this repository.

Google Gemini AI

Google Gemini is a generative AI model that can generate text (like ChatGPT) and answer questions about images. You can explore the model through a UI in AI Studio. To use it from your code, you can start with our Node.js example and read the documentation.

Resources