Callback and promise based HTTP client that supports SSL pinning for React Native.
Using NPM:
npm install react-native-pinch
Using Yarn:
yarn add react-native-pinch
react-native link react-native-pinchYou need rnpm (npm install -g rnpm)
rnpm link react-native-pinchAdd the following line to your build targets in your Podfile
pod 'RNPinch', :path => '../node_modules/react-native-pinch'
Then run pod install
- in
android/app/build.gradle:
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-pinch')
}- in
android/settings.gradle:
...
include ':app'
+ include ':react-native-pinch'
+ project(':react-native-pinch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pinch/android')- in
MainApplication.java:
+ import com.localz.PinchPackage;
public class MainApplication extends Application implements ReactApplication {
//......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new PinchPackage(),
new MainReactPackage()
);
}
......
}- in
MainActivity.java:
+ import com.localz.PinchPackage;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new PinchPackage(),
new MainReactPackage()
);
}
}Before you can make requests using SSL pinning, you first need to add your .cer files to your project's assets.
- Place your
.cerfile undersrc/main/assets/.
Examples are using the ES6 standard
Requests can be made by using the fetch(url[, config, [callback]]) method of Pinch.
import pinch from 'react-native-pinch';
pinch.fetch('https://my-api.com/v1/endpoint', {
method: 'post',
headers: { customHeader: 'customValue' },
body: '{"firstName": "Jake", "lastName": "Moxey"}',
sslPinning: {
cert: 'my-cool-cert'
}
})
.then(res => console.log(`We got your response! Response - ${res}`))
.catch(err => console.log(`Whoopsy doodle! Error - ${err}`))import pinch from 'react-native-pinch';
pinch.fetch('https://my-api.com/v1/endpoint', {
method: 'post',
headers: { customHeader: 'customValue' },
body: '{"firstName": "Jake", "lastName": "Moxey"}',
sslPinning: {
cert: 'my-cool-cert'
}
}, (err, res) => {
if (err) {
console.error(`Whoopsy doodle! Error - ${err}`);
return null;
}
console.log(`We got your response! Response - ${res}`);
}){
bodyString: '',
headers: {},
status: 200,
statusText: 'OK'
}