<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anesu Murakata</title>
    <description>The latest articles on DEV Community by Anesu Murakata (@anesumurakata).</description>
    <link>https://dev.to/anesumurakata</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F607069%2F3eb4eef4-c7ef-440f-b4e4-2d1b76e4834a.jpeg</url>
      <title>DEV Community: Anesu Murakata</title>
      <link>https://dev.to/anesumurakata</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anesumurakata"/>
    <language>en</language>
    <item>
      <title>Creating and Hosting a Personal API with Flask and Code Capsules</title>
      <dc:creator>Anesu Murakata</dc:creator>
      <pubDate>Thu, 01 Apr 2021 14:39:26 +0000</pubDate>
      <link>https://dev.to/ritza/creating-and-hosting-a-personal-api-with-flask-and-code-capsules-5452</link>
      <guid>https://dev.to/ritza/creating-and-hosting-a-personal-api-with-flask-and-code-capsules-5452</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodecapsules.io%2Fdocs%2Fcontent%2Fimages%2F2021%2F03%2FCodeCpasules_API%402x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodecapsules.io%2Fdocs%2Fcontent%2Fimages%2F2021%2F03%2FCodeCpasules_API%402x.jpg" alt="header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an API and Why Care?
&lt;/h2&gt;

&lt;p&gt;An &lt;em&gt;API&lt;/em&gt;, or Application Programming Interface, is a tool enabling developers to interact with data online. Imagine: you navigate to some website and see your location's temperature displayed on their homepage. How did they present this information?&lt;/p&gt;

&lt;p&gt;Without a doubt, they used an API. APIs are hosted on a server and operate as an access point between the user and some data. &lt;/p&gt;

&lt;p&gt;Part of this guide takes a look at the &lt;a href="https://weatherstack.com/" rel="noopener noreferrer"&gt;WeatherStack&lt;/a&gt; API – an API providing weather data. For the website to retrieve your location's temperature, they would've sent a request to an API like WeatherStack. In the request, they would include information about your computer's location. WeatherStack's API would then return weather data related to your locale, such as the temperature and cloud cover. The weather website will then display this data on their homepage for you to view. &lt;/p&gt;

&lt;p&gt;In this tutorial, we'll learn how to create a personal API with Python (using &lt;a href="https://palletsprojects.com/p/flask/" rel="noopener noreferrer"&gt;Flask&lt;/a&gt;). Our API will use data from the &lt;a href="https://weatherstack.com/" rel="noopener noreferrer"&gt;WeatherStack&lt;/a&gt; and &lt;a href="https://openexchangerates.org/" rel="noopener noreferrer"&gt;OpenExchangeRates&lt;/a&gt; APIs to give us up-to-the-minute USD exchange rates and the temperature of a given city. &lt;/p&gt;

&lt;p&gt;We'll host our API on &lt;a href="https://codecapsules.io/" rel="noopener noreferrer"&gt;Code Capsules&lt;/a&gt; so that anyone will be able to request information from it, no matter their location. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before starting, we'll need a &lt;a href="//www.github.com"&gt;GitHub&lt;/a&gt; account and knowledge of how to push code &lt;a href="https://docs.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line" rel="noopener noreferrer"&gt;from a local repository to a remote repository&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Also ensure you've installed the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.python.org/downloads/" rel="noopener noreferrer"&gt;Python&lt;/a&gt; 3.XX+&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://virtualenv.pypa.io/en/latest/installation.html" rel="noopener noreferrer"&gt;Virtualenv&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up Our Environment
&lt;/h2&gt;

&lt;p&gt;First, let's set up a virtual Python environment using Virtualenv. Virtualenv provides a clean Python install with no third-party libraries or packages, allowing us to work on this project without interfering with the dependencies of our other projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal and create an empty folder.&lt;/li&gt;
&lt;li&gt;Navigate to the folder via your terminal, and enter &lt;code&gt;virtualenv env&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To activate the virtual environment, enter one of the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux/MacOSX&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source env&lt;/span&gt;/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\env\Scripts\activate.bat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the virtual environment has activated correctly, you'll see &lt;code&gt;(env)&lt;/code&gt; to the left of your name in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage1.png" alt="command prompt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing the Dependencies
&lt;/h3&gt;

&lt;p&gt;Now that we've activated the virtual environment, let's take a look at the packages we'll use to create our API: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://palletsprojects.com/p/flask/" rel="noopener noreferrer"&gt;Flask&lt;/a&gt; is a minimal web development framework for Python. Flask provides resources and tools for building and maintaining web applications, websites, and more.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gunicorn.org/" rel="noopener noreferrer"&gt;Gunicorn&lt;/a&gt; is a &lt;a href="https://medium.com/analytics-vidhya/what-is-wsgi-web-server-gateway-interface-ed2d290449e" rel="noopener noreferrer"&gt;WSGI&lt;/a&gt; server that will help serve our Python application (the API hosted on Code Capsules). &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pypi.org/project/requests/" rel="noopener noreferrer"&gt;Requests&lt;/a&gt; is a Python library we will use to interact with APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From your terminal where you activated the virtual environment, install these packages with &lt;code&gt;pip3 install flask gunicorn requests&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Registering Accounts on OpenExchangeRates and WeatherStack
&lt;/h2&gt;

&lt;p&gt;Our API will return the current temperature of a chosen city and the USD exchange rates for three currencies. We'll create our API by combining data from two other APIs – &lt;a href="https://weatherstack.com" rel="noopener noreferrer"&gt;WeatherStack&lt;/a&gt; and &lt;a href="https://openexchangerates.org/" rel="noopener noreferrer"&gt;OpenExchangeRates&lt;/a&gt;. As their names suggest, WeatherStack will provide the temperature data, and OpenExchangeRates the exchange rate data. &lt;/p&gt;

&lt;p&gt;Registering an account is required so that we can receive a unique &lt;em&gt;API key&lt;/em&gt;. An API key is a password that lets us use a particular API. In APIs with more sensitive data, these are used to prevent unauthorised access, but for open APIs like WeatherStack and OpenExchangeRates, they're used for &lt;a href="https://en.wikipedia.org/wiki/Rate_limiting" rel="noopener noreferrer"&gt;rate limiting&lt;/a&gt; to prevent users from sending too many requests at once and overwhelming the system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating our accounts
&lt;/h3&gt;

&lt;p&gt;First, let's register an account on OpenExchangeRates. Navigate to &lt;a href="https://openexchangerates.org/signup/free" rel="noopener noreferrer"&gt;https://openexchangerates.org/signup/free&lt;/a&gt; and:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign up and log in.&lt;/li&gt;
&lt;li&gt;On the dashboard, click "App IDs". &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Save&lt;/strong&gt; your "App ID" (API key) on your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage2.png" alt="image2"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Obtaining the WeatherStack API key is similar:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a free account on &lt;a href="https://weatherstack.com/product" rel="noopener noreferrer"&gt;WeatherStack&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Log in and save the API key presented to you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage3.png" alt="image3"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we can retrieve data from the OpenExchangeRates and WeatherStack APIs using our API keys. Let's try that out now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting exchange rates
&lt;/h3&gt;

&lt;p&gt;First, let's see how requesting data from OpenExchangeRates works. Create a file named &lt;code&gt;app.py&lt;/code&gt; and open it.&lt;/p&gt;

&lt;p&gt;To request data from an API, we need an &lt;em&gt;endpoint&lt;/em&gt; for the type of data we want. APIs often provide multiple endpoints for different information – for example, a weather API may have one endpoint for temperature and another for humidity.&lt;/p&gt;

&lt;p&gt;In the code below, the &lt;code&gt;EXCHANGE_URL&lt;/code&gt; variable contains the OpenExchangeRates endpoint for retrieving the latest exchange rates. Enter it in your &lt;code&gt;app.py&lt;/code&gt; file now, replacing &lt;code&gt;YOUR-API-KEY-HERE&lt;/code&gt; with the &lt;strong&gt;OpenExchangeRates&lt;/strong&gt; API key you saved earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://openexchangerates.org/api/latest.json?app_id=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;exchange_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we're using the &lt;code&gt;requests&lt;/code&gt; module to fetch data from the API. It does this over HTTPS, the same way your browser would. In fact, if you copy the value of &lt;code&gt;EXCHANGE_URL&lt;/code&gt; to your browser now, you'll see exactly what data your code is fetching.&lt;/p&gt;

&lt;p&gt;Note the format of the URL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;https://openexchangerates.org&lt;/code&gt; is the website.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/api/&lt;/code&gt; is the path containing the API portion of the website.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;latest.json&lt;/code&gt; is the API endpoint which returns the latest exchange rates.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;?app_id=YOUR-API-KEY-HERE&lt;/code&gt; specifies our password for accessing the API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OpenExchangeRates has many other endpoints, each of which provides a different set of data. For example, you could request data from the &lt;code&gt;historical&lt;/code&gt; endpoint (&lt;code&gt;https://openexchangerates.org/api/historical/&lt;/code&gt;) to access past exchange rates.&lt;/p&gt;

&lt;p&gt;Now let's print the data using the &lt;code&gt;.json()&lt;/code&gt; method. This method converts the data from raw text into in &lt;a href="https://www.json.org/json-en.html" rel="noopener noreferrer"&gt;JSON&lt;/a&gt; (Javascript Object Notation), which we can work with like a Python dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exchange_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When running the program, you will see a lot of output. This is because we are currently retrieving every exchange rate OpenExchangeRates provides. Let's modify the code to only receive exchange rates from USD to EUR, CAD, and ZAR. &lt;/p&gt;

&lt;p&gt;Add the following lines below &lt;code&gt;EXCHANGE_URL&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;symbols&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ZAR,EUR,CAD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;exchange_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then change your &lt;code&gt;print&lt;/code&gt; statement as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(exchange_data.json()['rates']) # Print only exchange rates

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we've included an &lt;code&gt;EXCHANGE_PARAMS&lt;/code&gt; variable. Providing &lt;em&gt;parameters&lt;/em&gt; to an API endpoint will alter which data is retrieved. The parameters available will depend on the API endpoint. You can find a list of parameters for the &lt;code&gt;latest&lt;/code&gt; endpoint &lt;a href="https://docs.openexchangerates.org/docs/latest-json" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In our case, we supplied the parameter &lt;code&gt;symbols&lt;/code&gt; with the three currencies we want data for. When you run the program again, you should only see three exchange rates.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Getting the temperature
&lt;/h3&gt;

&lt;p&gt;Now that we've obtained the exchange rates, we can retrieve the temperature for a city. Let's modify the program by adding the following below the &lt;code&gt;print&lt;/code&gt; statement. Make sure to replace &lt;code&gt;YOUR-API-KEY-HERE&lt;/code&gt; with the &lt;strong&gt;WeatherStack&lt;/strong&gt; API key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;WEATHER_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://api.weatherstack.com/current?access_key=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;query&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cape Town&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;weather&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;WEATHER_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;current&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# will print only the temperature; print without indexing to see all the values returned!
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we retrieve the temperature for Cape Town, South Africa. You can replace "Cape Town" with another city of your choice to see its temperature. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our API
&lt;/h2&gt;

&lt;p&gt;Now we'll get to creating the API with Flask. Our API will package the WeatherStack and OpenExchangeRates data together in a single endpoint.&lt;/p&gt;

&lt;p&gt;This means we can build other applications later which will be able to retrieve all of the data above by calling &lt;code&gt;requests.get(MY_CODE_CAPSULES_URL)&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Beginning steps with Flask
&lt;/h3&gt;

&lt;p&gt;First, we can remove all the print statements in our &lt;code&gt;app.py&lt;/code&gt; file. Afterwards, edit the file accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jsonify&lt;/span&gt; &lt;span class="c1"&gt;# Import Flask, import jsonify to return JSON info
&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Create main page of web-application
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to my API!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;# Display text on main page
&lt;/span&gt;
&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://openexchangerates.org/api/latest.json?app_id=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;symbols&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ZAR,EUR,CAD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;exchange_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  

&lt;span class="n"&gt;WEATHER_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://api.weatherstack.com/current?access_key=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;query&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cape Town&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;weather&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;WEATHER_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# Run the application
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After instantiating a Flask object, we add &lt;code&gt;@app.route('/')&lt;/code&gt;. The &lt;code&gt;@&lt;/code&gt; symbol is known as a &lt;a href="https://realpython.com/primer-on-python-decorators/" rel="noopener noreferrer"&gt;Python decorator&lt;/a&gt; – their use isn't very important for our application. Just understand that the below creates the homepage for your API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`/`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to my API!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once it's hosting it on Code Capsules, you'll see "Welcome to my API!" when you visit its URL.&lt;/p&gt;

&lt;p&gt;Next, we'll implement the ability to "get" (using &lt;code&gt;requests.get()&lt;/code&gt;) our data from the API when it's hosted. &lt;/p&gt;

&lt;h3&gt;
  
  
  Combining the APIs
&lt;/h3&gt;

&lt;p&gt;We've already written code to retrieve our data – now we just need to combine it and create an endpoint to fetch it. We'll do this by wrapping our retrieval code in the function below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/get&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# Add an endpoint to access our API
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://openexchangerates.org/api/latest.json?app_id=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;symbols&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ZAR,EUR,CAD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;exchange_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXCHANGE_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EXCHANGE_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  

    &lt;span class="n"&gt;WEATHER_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://api.weatherstack.com/current?access_key=YOUR-API-KEY-HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;query&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cape Town&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;weather&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;WEATHER_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;WEATHER_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;usd_rates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exchange_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;curr_temp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;current&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@app.route('/get', methods=['GET'])&lt;/code&gt; adds an endpoint, &lt;code&gt;/get&lt;/code&gt;, allowing us to retrieve data from the API. When Code Capsules gives us a URL for our API, we'll be able to use this URL plus the endpoint to &lt;code&gt;requests.get()&lt;/code&gt; data from our API. This is identical to how we've obtained data from OpenExchangeRates and WeatherStacks.&lt;/p&gt;

&lt;p&gt;Next, the statement below returns our data in JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;usd_rates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exchange_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;curr_temp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;current&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the exchange rate data is stored under &lt;code&gt;'usd_rates'&lt;/code&gt; and the temperature data under &lt;code&gt;curr_temp&lt;/code&gt;. This means that if we request our data and store it in a variable like &lt;code&gt;my_data&lt;/code&gt;, we'll be able to print out the exchange rates by executing &lt;code&gt;print(my_data['usd_rates'])&lt;/code&gt;, and print the temperature by executing &lt;code&gt;print(my_data['curr_temp'])&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The API is complete – only a few steps left before hosting it on Code Capsules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Freezing Requirements and Creating the Procfile
&lt;/h2&gt;

&lt;p&gt;Before sending our API to GitHub (so Code Capsules can host it), we need the &lt;code&gt;requirements.txt&lt;/code&gt; file, and a Procfile.  &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;requirements.txt&lt;/code&gt; file contains information about the libraries we've used to make our API, which will allow Code Capsules to install those same libraries when we deploy it. To create this file, first ensure your terminal is still in the virtual environment. Then, in the same directory as the &lt;code&gt;app.py&lt;/code&gt; file, enter &lt;code&gt;pip3 freeze &amp;gt; requirements.txt&lt;/code&gt; in your terminal.&lt;/p&gt;

&lt;p&gt;Next, create a new file named &lt;code&gt;Procfile&lt;/code&gt; in the same directory. Open the &lt;code&gt;Procfile&lt;/code&gt; and enter:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;web: gunicorn app.py:app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This tells Code Capsules to use the Gunicorn WSGI server to serve the HTTP data sent and recieved by our Flask API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosting the API on Code Capsules
&lt;/h2&gt;

&lt;p&gt;The API is now ready to host on Code Capsules. Follow these steps to get it online:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a remote repository on Github.&lt;/li&gt;
&lt;li&gt;Push the &lt;code&gt;Procfile&lt;/code&gt;, &lt;code&gt;requirements.txt&lt;/code&gt;, and &lt;code&gt;app.py&lt;/code&gt; files to the repository.&lt;/li&gt;
&lt;li&gt;Link the repository to your Code Capsules account.&lt;/li&gt;
&lt;li&gt;Create a new Team and Space (as necessary).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the repository linked to Code Capsules, we just need to store the API on a Capsule:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new Capsule.&lt;/li&gt;
&lt;li&gt;Choose Backend Capsule and continue.&lt;/li&gt;
&lt;li&gt;Select your product type and GitHub repository, click next. &lt;/li&gt;
&lt;li&gt;Leave the "Run Command" field blank (our &lt;code&gt;Procfile&lt;/code&gt; handles this step).&lt;/li&gt;
&lt;li&gt;Create the Capsule.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once the Capsule has built, the API is hosted! Let's take a quick look at how to interact with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Viewing and interacting with our API
&lt;/h3&gt;

&lt;p&gt;Once the Capsule has been built, Code Capsules will provide you with a URL (found in the "Overview" tab). Enter the URL in your browser, and you'll be greeted with "Welcome to my API!". To view the API data, add &lt;code&gt;/get&lt;/code&gt; to the end of the URL. &lt;/p&gt;

&lt;p&gt;Depending on your browser (Google Chrome was used below), you'll see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fritza-co%2FCodeCapsules%2Fraw%2Fmain%2FserverlessFirstSteps%2F3.Creating-and-hosting-api-with-flask-codecapsules%2Fimages%2Fimage4.png" alt="image4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now try interacting with the API through code. In a new file, enter the following, replacing the URL with your Code Capsules URL (ensure &lt;code&gt;/get&lt;/code&gt; is at the end of the URL):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;MY_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://my-code-capsules-url.codecapsules.space/get&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;api_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MY_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All done!&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;We've learned a lot about APIs; how to interact with them, how to use API endpoints, and how to create and host an API with Flask and Code Capsules. If you'd like a more in-depth look at APIs, check out &lt;a href="https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're interested in learning more about Flask or want to know what else you can do with it, start with their &lt;a href="https://flask.palletsprojects.com/en/1.1.x/tutorial/" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt; or their &lt;a href="https://flask.palletsprojects.com/en/1.1.x/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>api</category>
    </item>
  </channel>
</rss>
