APIs are everywhere, including on the internet. There are a bunch of different types of APIs, but a very common style and the type that Retrofit is built to work with is called a REST API.
- [Instructor] What is the Retrofit API? As the website puts it, it is a type-safe HTTP client for Android and Java. But what does that mean? To understand exactly what Retrofit is and why we would want to use it in a Android application, we need to know a little bit about how devices on the internet communicate with one another. For the most part, they use a set of rules to determine how data should be shared called communication protocols.
Primarily the Internet Protocol Suite, which is a set of communications protocols that specifies how data should be packaged, addressed, routed, and received. This suite of protocols is commonly referred to as the TCP/IP model, but please keep in mind that TCP and IP are two specific protocols within this suite. HTTP and HTTPS are two other protocols within that suite that you are probably familiar with among many others.
These stand for Hypertext Transfer Protocol and Hypertext Transfer Protocol Secure. Using these protocols, computers communicate with one another through a defined message structure. This is defined as the HTTP 1.1 standard, which is detailed in a publication by the Internet Engineering Task Force or the IETF called an RFC 7230, which you can read all about here if you feel up for it.
There has been one major revision in this standard, HTTP/2, which was published in 2015, but it was designed to optimize data transmission and does not change the syntax defined in 1.1. When you are browsing the web, you may have noticed that the website URLs usually start with http or https. This is because these are the protocols being used by those websites, the server, and your browser, Chrome, Firefox, or Edge for example, which is the client, to communicate with one another and display the page and everything it contains.
The content isn't always visual though. Sometimes it is just data in any number of different formats. These are web services. REST is a common architecture style that is used by some web services along with the HTTP and HTTPS protocols. REST stands for Representational State Transfer, and is a set of rules used when creating a web service that utilizes a set of standardized methods for communicating called HTTP methods.
Web services that conform to these set of rules are called RESTful APIs. So let's return to our original question. What is the Retrofit API? It is a Java API that makes communicating with a RESTful API simple by enabling you to convert the RESTful API's HTTP methods into methods you can execute in your application's code. It means this request can be made by writing a line of code that looks like this.
- REST API basics
- Methods for reading and writing data
- Defining data models with Retrofit
- Implementing an API interface
- Getting data with a Retrofit call
- Authorizing requests
- Putting, deleting, and posting data
- Customizing the data converter
- Working with the request and response headers