API Christiaan - pmvdbijl7/matching-app GitHub Wiki

What's an API?

APIs are like waiters at a restaurant, you ask them to get something and they do just that (hopefully). API is an abbreviation for Application Programming Interface (Hoffman, 2018). It helps you save time because you dont have to fill an entire database manually, instead it provides us with loads of usefull data. In our app I implemented an API for retrieving movie data on specific movies and TV shows.

A model of how an API works

An overview of how an API works, source

Web service APIs

The following are the most used web services (Rungta, 2021):

  • SOAP: This protocol was created before REST. The main idea begin it was to make sure programs build on different platforms and in different programming languages could exchange data securely.
  • REST: Design especially for working with things like media components, files or even objects on hardware devices. Services defined on the REST principles can be called RESTful web services. REST uses HTTP requests like GET, POST, PUT and DELETE for working with components.

Web services use adresses, i.e. a Web URL, to provice access to their services.

The services about to be mentiones are the most used types of web service APIs.

API Usage in our project

In our project I wanted to use an API to render data on films users like. For example a user would pick his favorite movies and using the API our app will load the poster and plot of said movie onto the users profile. I query the data using axios. The movie var is read from the users request.

let posters = await axios({
  method: 'GET',
  url: `http://www.omdbapi.com/?apikey=${process.env.API_KEY}&t=${movie}`,
});

This request gives the data on a certain movie which looks like this: The JSON the API sends back

Now I want to add this data to the database. I do this by creating an empty array and pushing the data into this array. Next I'll set the posters array of the user model to be the filled array.

Sources

Hoffman, C. (2018, 20 march). What Is an API? How-To Geek. https://www.howtogeek.com/343877/what-is-an-api/

Rungta, K. (2021, 18 march). API vs Web Service: What’s the Difference? Guru99. https://www.guru99.com/api-vs-web-service-difference.html

⚠️ **GitHub.com Fallback** ⚠️