resttesttest icon indicating copy to clipboard operation
resttesttest copied to clipboard

PLEASE HELP, can't get our http request working.

Open OwsonOMG opened this issue 5 years ago • 0 comments

we can't use the GET function https://resttesttest.com/ to return from this address: _https://databasefujr.com/functions/getunitstatus

below is our backend codes, anyone please let me know what's wrong with our coding? we using WIX corvid to write it.
import {ok, notFound, serverError, created, badRequest} from 'wix-http-functions'; import wixData from 'wix-data'; // URL to call this HTTP function from your published site looks like: // Premium site - https://mysite.com/_functions/example/multiply?leftOperand=3&rightOperand=4 // Free site - https://username.wixsite.com/mysite/_functions/example/multiply?leftOperand=3&rightOperand=4

// URL to test this HTTP function from your saved site looks like: // Premium site - https://mysite.com/_functions-dev/example/multiply?leftOperand=3&rightOperand=4 // Free site - https://username.wixsite.com/mysite/_functions-dev/example/multiply?leftOperand=3&rightOperand=4

export function get_example(request) { const response = { "headers": { "Content-Type": "application/json" } };

// Get operation from the request path
const operation = request.path[0]; // "multiply"
const leftOperand = parseInt(request.query["leftOperand"], 10); // 3
const rightOperand = parseInt(request.query["rightOperand"], 10); // 4

// Perform the requested operation and return an OK response
// with the answer in the response body
switch (operation) {
case 'add':
	response.body = {
		"sum": leftOperand + rightOperand
	};
	return ok(response);
case 'multiply':
	response.body = {
		"product": leftOperand * rightOperand
	};
	return ok(response);
default:
	// If the requested operation was not found, return a Bad Request
	// response with an error message in the response body
	response.body = {
		"error": "unknown operation"
	};
	return ok(response);
	//return badRequest(response);
}

}

export function get_testget(request) { const response = { "headers": { "Content-Type": "application/json" } };

response.body = {"bodytilte": "bodycontent"}; response.status = 200;

 return Promise.resolve(ok(response));

}

export async function get_getunitstatus(request){ const response = { "headers": { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", "Access-Control-Allow-Headers": ",User-Agent,,content-type, pragma, x-unrealengine-agent",

	}
};

//let queryresult; await wixData.query("BookingAppDatabase") .ascending("entry") .find() .then((results) => { //console.log(results.items.length); response.body = {"items": results.items}; })

response.status = 200; console.log("getunitstatus_returning");

return ok(response);

}

export function post_testPost(request) {

return request.body.text() .then( (body) => {

  // insert the info from the body somewhere

  return ok(request);
} );

}

OwsonOMG avatar May 18 '19 09:05 OwsonOMG