2017-02-07 11:03:16 +00:00
# react-native-http-bridge
2017-02-06 13:40:44 +00:00
HTTP Server for [React Native ](https://github.com/facebook/react-native )
2017-02-07 11:03:16 +00:00
Supports only POST-requests and one-way communication. Created for [Status.im ](https://github.com/status-im )
2017-02-06 13:40:44 +00:00
## Install
```shell
2017-02-07 11:03:16 +00:00
npm install --save react-native-http-bridge
2017-02-06 13:40:44 +00:00
```
## Automatically link
#### With React Native 0.27+
```shell
2017-02-07 11:03:16 +00:00
react-native link react-native-http-bridge
2017-02-06 13:40:44 +00:00
```
## Example
First import/require react-native-http-server:
```js
2017-02-07 11:03:16 +00:00
var httpBridge = require('react-native-http-bridge');
2017-02-06 13:40:44 +00:00
```
2017-02-07 11:03:16 +00:00
Initalise the server in the `componentWillMount` lifecycle method. You need to provide a `port` and a callback where requests will be captured. Currently there is no way to return responses.
2017-02-06 13:40:44 +00:00
```js
componentWillMount(){
2017-02-07 11:03:16 +00:00
// initalize the server (now accessible via localhost:1234)
httpBridge.start(5561, function(request) {
// request.url
// request.postData
2017-02-06 13:40:44 +00:00
});
}
```
Finally, ensure that you disable the server when your component is being unmounted.
```js
componentWillUnmount() {
2017-02-07 11:03:16 +00:00
httpBridge.stop();
2017-02-06 13:40:44 +00:00
}
```