Files
flipper/docs/setup/protobuf-retrofit-plugin.mdx
Harold Martin b0cbf39a1a Export protobuf definitions from Retrofit (#2084)
Summary:
https://github.com/facebook/flipper/pull/2080 enables storing protobuf definitions and displaying payloads in the network inspector plugin. However, describing those definitions in ProtobufJS format can be time consuming and error prone. This PR enables sending definitions from an entire Retrofit service with a single line.

## Changelog
* Adds a retrofit2-protobuf plugin

Pull Request resolved: https://github.com/facebook/flipper/pull/2084

Test Plan:
Used as a single line per service, ie:
`SendProtobufToFlipperFromRetrofit(baseUrl, PersonService::class.java)`

For more details see demo app in https://github.com/hbmartin/protobuf_java_to_protobufjs

Reviewed By: mweststrate

Differential Revision: D27507872

Pulled By: passy

fbshipit-source-id: 859d7636c9512de0abde0aa1dcb2e023851369cf
2021-04-07 13:31:23 -07:00

37 lines
1.3 KiB
Plaintext

---
id: protobuf-retrofit-plugin
title: Protobut + Retrofit Setup
sidebar_label: Protobut + Retrofit
---
## Gradle Dependencies
Ensure that you already have an explicit dependency in your application's
`build.gradle` including the plugin dependency, e.g.
```groovy
dependencies {
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-protobuf:2.9.0"
// update version below to match latest Flipper client app
debugImplementation "com.facebook.flipper:flipper:0.84.0"
debugImplementation "com.facebook.flipper:flipper-network-plugin:0.84.0"
debugImplementation "com.facebook.flipper:flipper-retrofit2-protobuf-plugin:0.84.0"
}
```
## Network Plugin Requirement
Ensure that `NetworkFlipperPlugin` is added as shown in the [Network setup guide](https://fbflipper.com/docs/setup/network-plugin#android)
## Sending Retrofit Service
Suppose you have a Retrofit service interface `PersonService` which has Protobuf body or return types. At the time you create your implementation, call the plugin with your `baseUrl` and service class:
```
import com.facebook.flipper.plugins.retrofit2protobuf.SendProtobufToFlipperFromRetrofit
...
val personService = retrofit.create(PersonService::class.java)
SendProtobufToFlipperFromRetrofit(baseUrl, PersonService::class.java)
```