@kingstinct/react-native-http-bridge

0.4.3 • Public • Published

react-native-http-bridge

A fork of react-native-http-bridge.

HTTP Server for React Native

Supports POST and GET-requests.

Install

npm install --save react-native-http-bridge

or

yarn add react-native-http-bridge

Automatically link

With React Native 0.27+

react-native link react-native-http-bridge

Example

First import/require react-native-http-server:

    import httpBridge from '@kingstinct/react-native-http-bridge';

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.

    componentWillMount(){

      // initalize the server (now accessible via localhost:1234)
      httpBridge.start(5561, function(request) {

          // request.url
          // request.postData

          //do something with the data
        return { code: 200, data: { hello: 'world' } }; //or return a promise
      });

    }

Finally, ensure that you disable the server when your component is being unmounted.

  componentWillUnmount() {
    httpBridge.stop();
  }

Package Sidebar

Install

npm i @kingstinct/react-native-http-bridge

Weekly Downloads

0

Version

0.4.3

License

MIT

Unpacked Size

377 kB

Total Files

47

Last publish

Collaborators

  • lordspace74
  • robertherber