API usually means how programs or services can request data from other services. Let's look at an example.
Twitter has a website where we can view tweets. By clicking on links, we can go to different addresses where different information is available: the tweets feed, the page of a specific tweet, your account, password reset, ad account, and so on.
- https://twitter.com/Hexlet_IO — page of a particular user
- https://twitter.com/hexlet_io/status/1583031921700851712?cxt=HHwWgMCqkajJh_grAAAA — page of a particular tweet
These pages return some HTML in which the information looks as we see it, with all the design elements. Twitter creators adapted it for small screens, so it opens from any device with a browser. But in addition to the website Twitter has a mobile application, which shows the same information, but with a more convenient interface, adapted to a particular phone.
Unlike the website, the mobile app is stored physically on the phone. It runs directly on it, so the application defines the entire appearance.
You also need pure data on Twitter's servers for the application to work. How do we download them to our phones? Ordinary page addresses don't work here because they return not data but ready-made HTML pages.
It is where APIs come to the rescue. Twitter provides specific HTTP addresses that make pure data available, not specific internet pages with a ready-made look and feel. Data at such addresses are given in a structured format, most often JSON. One service packs the data into JSON format, and the other, which follows the data, unpacks it from JSON and uses it internally for display.
Let's observe an example of a user request:
# The address to which the app returns the list of specified users
# In this case, one user is requested
https://api.twitter.com/2/users/by?usernames=hexletHQ
# This is the JSON structure you get in response:
{
"data": [
{
"created_at": "2013-12-14T04:35:55.000Z",
"id": "2244994945",
"name": "HexletHQ",
"description": "Hexlet - programming courses",
"pinned_tweet_id": "1464165859761573893",
"username": "hexlethq"
},
],
}
The purpose of this API is to provide convenient access to Twitter data. And this API is used both by Twitter mobile applications and third-party services that manage Twitter. For example, marketers use services that automatically publish tweets on a schedule.
The Twitter API is an example of an HTTP API. It works over the HTTP protocol, through which browsers load and display sites. HTTP is the most common and convenient way to make APIs for public Internet services. The Internet leans on it, so any programming language supports it. After all, it's a simple protocol that everyone involved in web or mobile app development knows one way or another.
In this course, we'll talk about what HTTP APIs are and how they work. We'll learn how to make queries to APIs to analyze and test them using Curl and the Postman service. Let's get acquainted with the OpenAPI standard (formerly Swagger), which describes the API format.
Preparation
The course focuses on how to build an API using HTTP, which we will study in another course. We recommend going through it if you're not familiar with HTTP.
Also, the courses about command line basics and HTML can be helpful.
Are there any more questions? Ask them in the Discussion section.
The Hexlet support team or other students will answer you.
For full access to the course you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.