react native post api call code example
Example 1: react native post api method
fetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue', }),}).then((response) => response.json()) .then((responseJson) => { return responseJson.movies; }) .catch((error) => { console.error(error); });
Example 2: how to sent get on react native
export const getNetworkImageBase64Format = () => {
const oReq = new XMLHttpRequest();
oReq.open('GET', url);
oReq.responseType = 'arraybuffer';
oReq.onload = () => {
if (oReq.status === 200) {
const base64 = Buffer.from(oReq.response).toString('base64');
console.log('base64', base64);
return base64;
}
return null;
};
oReq.send();
};