Hi all trust this finds you well. Im struggling on something relatively simple and for the life of me I cant figure it out.
Please leave me a place to donate for the answer if required.
I have opened up my API CORS service with nominal test data. Ill chnage the CORS key once I am able to move forwards
Im trying to integrate WIX Fetch() with RestDB.io I have managed to get a DB stood up an passing the data to the console of the browser. I cant get the data posted to the browser to display in the text element I have put on a page!
Please it the URL in chrome here : https://members-7478.restdb.io/rest/user-device?key=5be43048ffebfc7d134d541d
Here is my backend code -
import { fetch } from ‘wix-fetch’;
export function userInfo() {
return fetch(“https://members-7478.restdb.io/rest/user-device”, {
method: "get",
mode: "cors",
cache: "no-cache",
headers: {
“Content-Type”: “application/json”,
“x-apikey”: “5be43048ffebfc7d134d541d”
}
})
.then( function (response) {
return response.json();
})
.then( function (text) {
console.log(‘Request successful’, text);
})
. catch(function (error) {
console.log(‘Request failed’, error)
});
}
Here is my Front end code
import {userInfo} from ‘backend/serviceModule’;
export function search_click_1(event) {
userInfo()
.then(response => {
$w(“#Result”).text =
“GID:” +response[0]._id + “\n”
+“UserID:” +response[0].UserID + “\n”
+“Device:” +response[0].Device;
})
}
Here is the browser console with response set to .text
{“consoleMethodCalls”:[[“log”,“Request successful [{"_id":"5be433afa9f23e3a00001a26","UserID":"apenwrig","Device":"laptimer12345"},{"_id":"5be9455fa9f23e3a0000833e","UserID":"apenwrig2","Device":"laptimer2"}]”]]}
Heres is the repsonse content set to .json
{“consoleMethodCalls”:[[“log”,“Request successful [ { _id: ‘5be433afa9f23e3a00001a26’,\n UserID: ‘apenwrig’,\n Device: ‘laptimer12345’ },\n { _id: ‘5be9455fa9f23e3a0000833e’,\n UserID: ‘apenwrig2’,\n Device: ‘laptimer2’ } ]”]]}
Im hoping its a parsing problem and not that the RestDB.io service is no compatible somehow.
I did check the format in a JSON tool and its valid.
Many thanks in advance
#3rdpartyapi #restapi #fetchdataparse