# data[].attributes.body
¿Qué es una API?

# data[].attributes.attachment_link.title
¿Qué es una API? - La mejor explicación en español

# data[].attributes.body
¿Qué es una API? explicación sencilla

# data[].attributes.attachment_link.description
Una API REST es una interfaz de programación de aplicaciones (API) que se ajusta a los principios de diseño del estilo arquitectónico de transferencia de estado representacional (REST).

# data[].attributes.body
Documentación JSONPlaceholder

# data[].attributes.attachment_link.description
You can copy paste the code in your browser console to quickly test JSONPlaceholder.

# data[].attributes.body
JSON en 5 minutos.

# data[].attributes.attachment_link.title
Aprende JSON en 10 minutos | Tutorial de JSON en Español

# data[].attributes.body
Google Maps API en Android Studio

# data[].attributes.attachment_link.title
How to Implement Google Map in Android Studio 2024 ( All Steps ) : All About Google Maps

# data[].attributes.body
Documentación Google Maps API

# data[].attributes.attachment_link.title
Guía de inicio rápido del SDK de Maps para Android | Maps SDK for Android | Google for Developers

# data[].attributes.attachment_link.description
Comienza un nuevo proyecto de Google Maps con tu app para Android hoy mismo. Aquí encontrarás todo lo que necesitas, desde la instalación del SDK hasta la compilación y ejecución de tu app.

# data[].attributes.body
Tutorial Retrofit 2

# data[].attributes.attachment_link.title
[TUTORIAL] RETROFIT 2 AVANZADO en KOTLIN - (POST,  GET, MULTIPART, HEADER...) - Android Studio 2022

# data[].attributes.body
Tutorial Postman

# data[].attributes.attachment_link.title
"Postman en Español: ¡El tutorial definitivo para el éxito en las pruebas API!

# data[].attributes.body
Descarga oficial Postman

# data[].attributes.attachment_link.readable_text
If you are using the Postman web client, you will need to also download the Postman desktop agent. The Postman agent overcomes the Cross Object Resource Sharing (CORS) limitations of browsers, and facilitates API request sending from your browser version of Postman.

Download Desktop Agent: macOS Linux Windows 64-bit Windows 32-bit

# data[].attributes.attachment_link.description
If you are using the Postman web client, you will need to also download the Postman desktop agent. The Postman agent overcomes the Cross Object Resource Sharing (CORS) limitations of browsers, and facilitates API request sending from your browser version of Postman.

# data[].attributes.body
Ejemplo Retrofit

# data[].attributes.attachment_link.readable_text
API Declaration

Annotations on the interface methods and its parameters indicate how a request will be handled.

Request Method

Every method must have an HTTP annotation that provides the request method and relative URL. There are eight built-in annotations: HTTP, GET, POST, PUT, PATCH, DELETE, OPTIONS and HEAD. The relative URL of the resource is specified in the annotation.

@GET("users/list")

You can also specify query parameters in the URL.

@GET("users/list?sort=desc")

URL Manipulation

A request URL can be updated dynamically using replacement blocks and parameters on the method. A replacement block is an alphanumeric string surrounded by { and }. A corresponding parameter must be annotated with @Path using the same string.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId);

Query parameters can also be added.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);

For complex query parameter combinations a Map can be used.

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);

Request Body

An object can be specified for use as an HTTP request body with the @Body annotation.

@POST("users/new")
Call<User> createUser(@Body User user);

The object will also be converted using a converter specified on the Retrofit instance. If no converter is added, only RequestBody can be used.

Form Encoded and Multipart

Methods can also be declared to send form-encoded and multipart data.

Form-encoded data is sent when @FormUrlEncoded is present on the method. Each key-value pair is annotated with @Field containing the name and the object providing the value.

@FormUrlEncoded
@POST("user/edit")
Call<User> updateUser(@Field("first_name") String first, @Field("last_name") String last);

Multipart requests are used when @Multipart is present on the method. Parts are declared using the @Part annotation.

@Multipart
@PUT("user/photo")
Call<User> updateUser(@Part("photo") RequestBody photo, @Part("description") RequestBody description);

Multipart parts use one of Retrofit's converters or they can implement RequestBody to handle their own serialization.

Header Manipulation

You can set static headers for a method using the @Headers annotation.

@Headers("Cache-Control: max-age=640000")
@GET("widget/list")
Call<List<Widget>> widgetList();

@Headers({
    "Accept: application/vnd.github.v3.full+json",
    "User-Agent: Retrofit-Sample-App"
})
@GET("users/{username}")
Call<User> getUser(@Path("username") String username);

Note that headers do not overwrite each other. All headers with the same name will be included in the request.

A request Header can be updated dynamically using the @Header annotation. A corresponding parameter must be provided to the @Header. If the value is null, the header will be omitted. Otherwise, toString will be called on the value, and the result used.

@GET("user")
Call<User> getUser(@Header("Authorization") String authorization)

Similar to query parameters, for complex header combinations, a Map can be used.

@GET("user")
Call<User> getUser(@HeaderMap Map<String, String> headers)

Headers that need to be added to every request can be specified using an OkHttp interceptor.

Synchronous vs. Asynchronous

Call instances can be executed either synchronously or asynchronously. Each instance can only be used once, but calling clone() will create a new instance that can be used.

On Android, callbacks will be executed on the main thread. On the JVM, callbacks will happen on the same thread that executed the HTTP request.

Retrofit Configuration

Retrofit is the class through which your API interfaces are turned into callable objects. By default, Retrofit will give you sane defaults for your platform but it allows for customization.

Converters

By default, Retrofit can only deserialize HTTP bodies into OkHttp's ResponseBody type and it can only accept its RequestBody type for @Body.

Converters can be added to support other types. Six sibling modules adapt popular serialization libraries for your convenience.

Gson: com.squareup.retrofit2:converter-gson

Jackson: com.squareup.retrofit2:converter-jackson

Moshi: com.squareup.retrofit2:converter-moshi

Protobuf: com.squareup.retrofit2:converter-protobuf

Wire: com.squareup.retrofit2:converter-wire

Simple XML: com.squareup.retrofit2:converter-simplexml

JAXB: com.squareup.retrofit2:converter-jaxb

Scalars (primitives, boxed, and String): com.squareup.retrofit2:converter-scalars

Here's an example of using the GsonConverterFactory class to generate an implementation of the GitHubService interface which uses Gson for its deserialization.

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .addConverterFactory(GsonConverterFactory.create())
    .build();

GitHubService service = retrofit.create(GitHubService.class);

Custom Converters

If you need to communicate with an API that uses a content-format that Retrofit does not support out of the box (e.g. YAML, txt, custom format) or you wish to use a different library to implement an existing format, you can easily create your own converter. Create a class that extends the Converter.Factory class and pass in an instance when building your adapter.

# data[].attributes.attachment_link.description
A type-safe HTTP client for Android and Java

# data[].attributes.body
Manejo de errores en API Rest

# data[].attributes.attachment_link.description
Esta Wiki pretende dar respuesta a las preguntas:

# data[].attributes.body
Mejores prácticas en seguridad de API REST

# data[].attributes.attachment_link.title
¿Qué es la seguridad API? 7 mejores prácticas de seguridad de API

# data[].attributes.attachment_link.description
La seguridad de API se refiere a las herramientas y mejores prácticas utilizadas para proteger las API del acceso no autorizado. API seguras con esta guía completa.