Files
flipper/docs/setup/network-plugin.mdx
generatedunixname89002005306973 0293a2a5fb Flipper Release: v0.81.0
Summary: Releasing version 0.81.0

Reviewed By: priteshrnandgaonkar

Differential Revision: D27114449

fbshipit-source-id: bcf89ccb61aedc7413d4031da42b10971e3808fa
2021-03-17 04:48:28 -07:00

78 lines
1.9 KiB
Plaintext

---
id: network-plugin
title: Network Setup
sidebar_label: Network
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
To use the network plugin, you need to add the plugin to your Flipper client instance.
## Android
The network plugin is shipped as a separate Maven artifact:
```groovy
dependencies {
debugImplementation 'com.facebook.flipper:flipper-network-plugin:0.81.0'
}
```
Once added to your dependencies, you can instantiate the plugin and add it to
the client:
```java
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
client.addPlugin(networkFlipperPlugin);
```
### OkHttp Integration
If you are using the popular OkHttp library, you can use the Interceptors system to automatically hook into your existing stack.
```java
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
new OkHttpClient.Builder()
.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin))
.build();
```
As interceptors can modify the request and response, add the Flipper interceptor after all others to get an accurate view of the network traffic.
## iOS
To enable network inspection, add the following pod to your Podfile:
```ruby
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version
```
Initialise the plugin in the following way:
<Tabs defaultValue="ios" values={[{ label: 'iOS', value: 'ios'}, { label: 'Swift', value: 'swift'}]}>
<TabItem value="ios">
```objective-c
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
[[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
```
</TabItem>
<TabItem value="swift">
```swift
import FlipperKit
client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter()))
```
</TabItem>
</Tabs>