React Native
React Native
REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)
See more REST Examples
Demonstrates how the autoReconnect argument to the Connect method is used.Chilkat React Native Downloads
import { Rest, Xml } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rest = new Rest();
// This example demonstrates the usage of the autoReconnect argument to the Connect method.
// When autoReconnect is on, subsequent REST method calls will automatically re-connect
// if necessary, using the same information (domain/IP address, port number, and TLS).
const bTls = false;
const port = 80;
const bAutoReconnect = true;
await rest.connectAsync('dev.markitondemand.com', port, bTls, bAutoReconnect);
// Get a stock quote:
rest.addQueryParam('symbol', 'AAPL');
let responseXml: string;
try {
responseXml = await rest.fullRequestNoBodyAsync('GET', '/MODApis/Api/v2/Quote');
} catch {
console.log(rest.lastErrorText);
return;
}
const xml = new Xml();
xml.loadXml(responseXml);
console.log(`AAPL LastPrice: ${xml.getChildContent('LastPrice')}`);
// Get another stock quote. If a new HTTP connection is required,
// the REST object will automatically connect using the same parameters.
rest.addQueryParam('symbol', 'AMZN');
try {
responseXml = await rest.fullRequestNoBodyAsync('GET', '/MODApis/Api/v2/Quote');
} catch {
console.log(rest.lastErrorText);
return;
}
xml.loadXml(responseXml);
console.log(`AMZN LastPrice: ${xml.getChildContent('LastPrice')}`);
}