Product Managers play a critical role in the success of a platform product by identifying and prioritizing features that drive developer adoption and create value for end-users. Understanding how to do simple API calls is important for several reasons:
In short, understanding how to do simple API calls is an essential skill for Platform Product Managers to be effective in their role, communicate better with developers, and create better products.
In this tutorial, you will:
REST stands for Representational State Transfer. It is a type of software architecture that is used to build web services. RESTful APIs [1] are designed to be simple and easy to use, and they are based on HTTP protocol. REST APIs use HTTP methods like GET, POST, PUT, and DELETE to perform operations on resources.
To learn how to make a simple API call using a RESTful API, you will need to choose an API to work with. There are many APIs available online that you can use for testing purposes.
For this tutorial, we will use the OpenWeatherMap API, which provides weather data for different locations.
To use the OpenWeatherMap API, you will need an API key. You can sign up for a free API key on the OpenWeatherMap website (be sure to follow the sign up instructions).
Once you have your API key, you can start making API calls.
Save the API Key, you will use it later in Step 5
HTTP methods are used to perform different operations on resources. The most common HTTP methods are GET, POST, PUT, and DELETE.
To make a GET request to the OpenWeatherMap API, you will need to construct a URL with your API key and the location you want to get weather data for. Here's an example URL:
https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key
Replace your_api_key with your actual API key. This URL will get weather data for London.
To make the API call, you can use a tool like cURL or Postman.
Use your terminal to execute this example cURL command. This command will output weather data for London.
{% code-block language="bash" %}
curl "https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key"
{% end-code-block %}
Replace your_api_key with your actual API key.
Your result in the terminal should look like this:
{% code-block language="json" %}
{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"stations","main":{"temp":279.37,"feels_like":277.44,"temp_min":277.84,"temp_max":280.42,"pressure":1018,"humidity":81},"visibility":10000,"wind":{"speed":2.57,"deg":100},"clouds":{"all":99},"dt":1682556608,"sys":{"type":2,"id":2075535,"country":"GB","sunrise":1682570439,"sunset":1682622928},"timezone":3600,"id":2643743,"name":"London","cod":200}
{% end-code-block %}
Congrats! You have made your first API call using cURL!
Open Postman and create a new request by clicking on the "New" button in the top-left corner of the screen. In the request builder, enter the URL of the API you want to call in the "Enter request URL" field. You can also select the request method (GET, POST, PUT, etc.) from the drop-down menu.
Click on the "Send" button to make the API call. Postman will display the response from the API in the lower half of the screen, including the status code, response headers, and response body.
Replace your_api_key with your actual API key.
If the API requires any parameters or headers, you can add them in the appropriate fields under the "Params" or "Headers" tabs.
Your result in the terminal should look like this:
Congrats! You have made your first API call using Postman!
As you learned in step 4, you could also try to make a POST, PUT or DELETE requests to the OpenWeatherMap API. However, the OpenWeatherMap API does not support those requests, so you will get an error:
It is critical to read the respective API Documentation to understand what is allowed, parameters, etc.
You would learn more about API Documentation in the next lesson.
In this tutorial, you learned the basics of RESTful APIs and HTTP methods (GET, POST, PUT, DELETE) and used tools like cURL and Postman to make a simple API calls.
[1] What Is A RESTful API?: https://aws.amazon.com/what-is/restful-api/
Be the first to know when this course is available