API NodeJS Express and Firebase for React native



我开发了一个API(node js,express和firebase(在我的本机应用程序中使用它 反应 瞧,我的API的结构:API:允许您选择一些尊重特定条件的用户,并在调用允许修改数据库中字段的函数后 Firebase:当我在浏览器上测试它时,API 运行良好。

这是我的 API 的结构:

    router.get ('/: senderID /: numberOfShare /: drop', function (req, res, next) { 
      // Code that allows users to be selected from the database FOREACH {
         // call to a function (function2) which allows to modify the data of users in the BDD
   }
    // define the function2 here { modify user data in the database
   } 
  }
我的

问题是:如何从我的反应原生应用程序中正确利用我的 API?

我做了一个测试,但没有工作。

测试:

shareDrop (drop, parent) {
   fetch ('192.168.1.4:3000/users/senderID/numberOfShare/drop',
    { method: 'GET', 
    headers: { 
      Accept: 'application / json', 
      'Content-Type': 'application / json', 
    } 
    params: JSON.stringify
     ({ 
       senderID: this.state.uid,
        numberOfShare: 'parent.state.numberOfShare',
        drop: drop 
      }), 
    }); 
}

确保您的info.plist允许本地主机或其他 API 与其通信。

信息列表

   <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>localhost</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
      </dict>
    </dict>

下面是我构建的一个存储库,演示了react-native应用如何与node服务器和mongo数据库进行通信。也许你可以在那里找到一些灵感。

最新更新