Up to this point, you’ve laid out your UI, and built the underlying logic to power the workflow. Now, we need to connect it to the data that will display a result on the screen after the barcode is scanned. The data we need for the barcode scanner app is stored in a modern database in the cloud that can be retrieved via an Application Programming Interface (API).
APIs are the foundation of how many modern applications are built because they are separate from the apps using them, and actually allow many different applications to make use of the same centralized data resources at the same time.
APIs can be accessed using URLs, which fetch the information we need in our app.
Making an HTTP Request with an API URL
Now we need to integrate with the API for the Barcode Scanner App, to make a connection to the OpenFoodFacts database. OpenFoodFacts has a specific URL to read data for a product, which we’ll use in this lesson. To make the app work, we need to make an HTTP request with the scanned barcode to this API URL.
An HTTP request is a message sent from a client (like a web browser or a mobile app) to a server, asking for some information or action. For example, when you type a web address (URL) into your browser's address bar and hit "enter," your browser sends an HTTP request to the server that hosts the website, asking for the web page associated with that URL. The server then responds with an HTTP response, which contains the information (in this case, the web page) that your browser requested.
HTTP requests can also be used to send data from a client to a server, for example when you fill out a form on a website and click "submit." In this case, the HTTP request contains the data you entered in the form, and the server can use this data to perform some action, like saving it to a database or sending an email.