A series of article that explains and demystifies the concepts about retrofit library.
This is the first article in this series:
- Android Series: A Practical Guide To Understanding Retrofit.
English is quite different from programming. An English man defines retrofit as a process of pimping or modifying a component or an accessory. An engineer or a programmer sees retrofit as a library.
What exactly is Retrofit?
Retrofit can be defined as a type-safe HTTP Client for Android and makes it easy to perform HTTP request, capturing and sending of structured data via REST technology.
How is retrofit type-safe?
Retrofit is type-safe because it ensures that every function called or operation defined is not performed until it verifies the actual type of data passed. This ‘verification stage’ or ‘type-checking’ takes place either at compile time i.e. syntactic analysis or at runtime i.e. actual running of the code for verification.
Some clients are developed in such a way that all variables can hold any type of data. These clients are contradicting the type-safe paradigm. Although, this has its advantages and disadvantages. I strongly believe that type-safe paradigm is better because these data types can be cast within limit if they are in agreement with the given formal grammar.
HELP! What is a REST Client or REST Server?
REST is a client-server architecture. It is an acronym which denotes: Representational State Transfer. It can be defined as a set of architectural standards, principles and guidelines for communication and to perform networking tasks between interoperable systems. It relies on HTTP protocol.Some of the principles include:
- Client-Server Architecture.
- Provides a uniform interface between components.
- Code on Demand.
- Layered System.
Retrofit is an example of a REST Client. It is a popular choice for android for managing HTTP requests and web service integration. Retrofit maps interfaces to web services operations. Implementation of these interfaces can make HTTP requests.
A RESTful Web Service on the other hand, which can also be called a REST API is based on representational state transfer architectural style and provides stateless operations for managing data using the structured web service annotations.
All RESTful Web Services are RESTful APIs. All RESTful APIs are not RESTful Web Services.
RESTful Web Service is dependent on HTTP verbs. These verbs represents the users action. Since REST relies on HTTP protocol, some of the HTTP verbs provides the action that enables the server to understand the type of request made. Some of these HTTP verbs include: GET, POST, PUT, DELETE, PATCH, TRACE, OPTIONS, CONNECT. These verbs will be used in our Retrofit library in the next article.
Retrofit is a cakewalk actually and I’d like you to follow me on this remarkable journey in mastering retrofit! Steel yourself 👊, brace yourself , as you charge on with fire! 🔥
P.S. If you can’t properly explain what API’s are or the only definition of API you know is Application Programming Interface, then you need to read this article by Maarten Dalmijn before you read the second article in this series.
Tobiloba Adejumo Newsletter
Join the newsletter to receive the latest updates in your inbox.