React Native
React Native
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat React Native Downloads
import { Rest, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
const rest = new Rest();
const bTls = true;
const bAutoReconnect = true;
try {
await rest.connectAsync('example.com', 443, bTls, bAutoReconnect);
} catch {
console.log(rest.lastErrorText);
return;
}
// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder. This avoids extra string conversions for large bodies.
const sbRequest = new StringBuilder();
sbRequest.append('{ "query": "chilkat" }');
rest.addHeader('Content-Type', 'application/json');
const sbResponse = new StringBuilder();
try {
await rest.fullRequestSbAsync('POST', '/api/search', sbRequest, sbResponse);
} catch {
console.log(rest.lastErrorText);
return;
}
let responseText: string;
try {
responseText = sbResponse.getAsString();
} catch {
console.log(sbResponse.lastErrorText);
return;
}
console.log(responseText);
}