can I call ASP.NET web API in React Native? - asp.net

I am new to react native. I want to know how to call ASP.NET api from react native. I don't have any URL to call inside fetch(). Can any one point me in right direction? It is fair to say I don't know much about ASP.NET web API.

There is good library available in React-native to handle api calls axios.
Installation
npm install axios for npm
yarn add axios for yarn users
Delete Request
axios.delete(URL).then((response)=>{
console.log(response);
//Do whatever you want to do with data
}).catch((error)=>{
console.log(error);
})
For more info read here(Its pretty good library to handle Api calls)
Axios Docs Github

Related

How to use Meteor services in Laravel website

I have an application build on Laravel.
Purpose of that application is to perform deliveries of goods.
It involves real-time tracking.
On the other hand I am building same application on Angular & Meteor.
Meanwhile I want to store the tracking data in Meteor database (mongodb).
Is there anyway to access Meteor server into my Laravel application to show the real-time tracking?
UPDATE
I tried Paulo Mogollón solution but I am facing this error:
Loading failed for the module with source file:///E:/Dev/laravelapp/node_modules/isomorphic-ws/index.d.ts
jsfiddle.net/Lrxjed8v
You can connect to your meteor server from anywhere using js with the simpleddp package, basically you do this.
npm install simpleddp isomorphic-ws --save
import ws from 'isomorphic-ws';
import simpleDDP from 'simpleDDP'; // ES6
const opts = {
endpoint: "ws://someserver.com/websocket",
SocketConstructor: ws,
reconnectInterval: 5000
};
const server = new simpleDDP(opts);
let userSub = server.subscribe("user_pub");
let otherSub = server.subscribe("other_pub", 'param1', 2); // you can specify arguments for subscription
(async ()=>{
await userSub.ready();
let nextSub = server.subscribe("next_pub"); // subscribing after sub is ready
await nextSub.ready();
//all subs are ready here
})();
You can find more examples and information in the package repo. Hope this takes you in the right direction.
Check that you have installed both modules npm install simpleddp isomorphic-ws --save.
Btw do you have node.js and npm installed? You should also configure you build manager like webpack. Or you can just download minified pre-compiled versions of these libs:
https://www.jsdelivr.com/package/npm/simpleddp
https://www.jsdelivr.com/package/npm/isomorphic-ws

C++ exception in 'nativeFlushQueueImmediate' when trying to access firebase on react native

I'm using https://rnfirebase.io in react native, and I'm getting this strange error when trying to call firebase sign in with phone
submit() {
firebase
.auth()
.signInWithPhoneNumber(this.phoneInput)
.then(confirmResult => console.log(confirmResult))
.catch(error => console.log(error));
}
What could it be?
This can happen when you've updated a native dependancy via npm but have not rebuilt the native side of your app.
The JS bundle will generally have the latest code immediately (after packager restart) but the native side will not until you rebuild your app on xcode/studio; therefore causing argument mismatches across React Native's bridge as both could be expecting very different arguments based on their previous versions.
The same applies in reverse, you've re-built your native app but not restarted the packager after updating a native dependancy via npm.

Error when running Firebase 3.0 with React Native

Just loaded firebase 3.0 with react-native and getting the error
[fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled
JS Exception: Can't find variable: document
Is react-native supported yet?
React-native code:
var firebase = require('firebase')
// Initialize Firebase
var config = {
apiKey: '<apiKey>',
authDomain: '<app>.firebaseapp.com',
databaseURL: 'https://<app>.firebaseio.com',
storageBucket: 'firebase-<app>.appspot.com'
};
firebase.config(config)
The newest version of firebase uses the document variables that are used in web applications and the RCTWebSocket or RCTView doesn't work the same way. (I'm not 100% sure about all the details). Anyway, you can just install an older version of firebase and it will work for you. Assuming you have npm installed follow these instructions.
Uninstall Firebase from your react-native project npm uninstall firebase --save
Install version 2.4.2 of firebase npm install firebase#2.4.2 --save
Happy Firebaseing!
Firebase JS SDK 3.1 just got released and is now compatible with React Native!
See release notes.
I was able to get Firebase 3.0.2 to load in React Native by putting the following in a .js file and importing it at the top of index.ios.js:
global.location = {
href: ''
};
global.screen = {
};
global.document = {
getElementsByTagName: function(){}
};
global.parent = global;
There may be other gotchas - I have not explored further than this but it might get Firebase 3 working for you.
Firebase 3.x is not supported in RN (yet..).
Issue
I think the issue relates to the auth module's dependency on the browser's window variable.
Will it be officially supported?
According to the following discussion thread from the Firebase team, they are presently working on 3.x support. There is however no release time frame set.
Google Groups Discussion.
Workarounds
Option 1 (with FB 2.x)
From Jacob Wenger:
If React Native support is a blocker for you, please continue to use
the 2.x.x SDKs until we resolve this issue. The 2.x.x SDKs will
continue to work, even after you migrate to the new console..`
Option 2 (with FB 3.x)
From Jacob Wenger:
As a "workaround" if you don't need auth (unlikely, I know, but still
worth mentioning), you should be able to do the following:
var app = require('firebase/app');
var database = require('firebase/database');
To use last version of Firebase with ReactNative you can use Firebase Bridge.
I have a demo app here.
Whilst the Firebase JS SDK does work on react native now, it is mainly built for the web and is generally not the best solution for react-native.
The Firebase Web SDK runs entirely on react native's JS thread, therefore affecting your application frame rate (the link explains this well).
In my tests, the native firebase SDK's has been roughly 2-3 times quicker than using the web SDK.
But on top of the potential performance impacts there's a lot of features you'll be unable to use with the web SDK on android/ios devices. For example:
Notifications / FCM
Offline capabilities
Storage upload/download
Firebase Crash Reporting
Analytics
Use of social authentication providers
The best approach would be to run with the native android/ios firebase sdk's and have a bridge between them and your js code (i.e. a native module setup).
Thankfully you don't have to implement this yourself, there's already modules out there to do this for you:
react-native-firebase for example mirrors the the web sdk's api js side but executes on the native side using the native android & ios firebase sdk's. It's fully compatible with any existing firebase js logic that you may have already implemented and is intended as a drop in replacement for the web sdk.
(disclaimer: I am the author of react-native-firebase)

How do I implement firebase using React native?

When I try to use npm install to use firebase with React native, I am getting errors.
Then when I try to use require for the firebase module, it says that the document can't be found.
Is there a way to utilize the firebase API with React native instead?
Firebase uses WebSockets, which currently is not supported by React Native. As of now, there is no good solution to integrate Firebase with React Native.
In lieu of requiring firebase as a module, you can indeed use the firebase API instead. If you were doing a simple get request, your fetch function would look like this:
var url = "https://YourDatabaseName.firebaseio.com/some/val.json";
fetch(url)
.then((response) => response.json())
.then((responseData) => {
console.log(responseData);
})
.done();
For more information, you can check out a blog post I wrote about the topic here:
http://anuj.io/using-firebase-api-with-react/
Firebase dev here — as of v0.4.4 of React Native, WebSockets are now supported, and as of version 2.2.5 of Firebase's JS client, we've implemented the integration with React Native. Therefore, Firebase should now work in your React Native app!
There is a known issue with our authentication methods at the moment, but we're working on it.
Let us know if you have any questions!

Firebase client on ReactNative

When using Firebase on ReactNative, it will show such error message:
can't find variable process
However, if I require firebase/lib/firebase-web.js manually, it will show:
can't find variable document
How can I resolve this?
I just went through the same issue while trying to use sockets.io in my react native app so hopefully I can help.
The reason that you cannot use firebase's node module is because there hasn't been a polyfill created yet for websockets support (which firebase is dependent on) in react native.
If you take a look at issue #619 in react native's repo you'll find the current discussion on creating a websockets api polyfill.
The way that we solved it is by using Jason's modified version of the sockets library and creating our own repo around just that file. Then we added the line below to our package.json dependencies.
"react-sockets": "crewapp/react-native-sockets-io"
The reason that Jason's version of the sockets.io client file works is because react-native is added as a user agent. You can find the code that makes this change at the top of the file:
window.navigator = {
userAgent: "react-native"
}
Once you've gone through these steps you should be able to require sockets.io / firebase as normal.
Just figuring it our. Pavan's answer is helpful, but it is not quite true when using with Firebase.
For firebase, please follow the steps:
Download the firebase-debug.js from wsExample. Or you can just install wsExample by npm and require the firebase-debug.js inside it.
Use badfortrains's forked React-Native:
"react-native": "git://github.com/badfortrains/react-native#WebSocket"
New the Firebase like this:
var firebase = require("../../firebase-debug.js");
var rootRef = new Firebase(Const.FB_ROOT);
Things should just work now!
I had issues with socket.io on React Native too, solution was to get notifications about new data and if data is big enough - get it by simple RESTfull request. in my case data was small enough to be sent all within notifications API.
I was using GCM service to send notification to phone from nodejs server. BTW, it uses less battery then socket connection and works great :)

Resources