My school project is to create a Frontend ( html+javascript with ajax calls) connected to a PHP backend that is connected to NodeJs json-server ( https://www.npmjs.com/package/json-server)
The issue I have is on my backend where I use EasyRDF PHP library to make the http request to json-server and I get the response as a string,but it looks like a json. How I can echo that response exactly the way json-server sends to that backend ( JSON format).
My php code sample:
$address="http://localhost:4000/categories"; //json-server is running on port 4000
$clienthttp=new EasyRdf\Http\Client($address);
$requestCategories=$clienthttp->request();
//string getBody() Get the response body as string
$resultJSON=$requestCategories->getBody();
echo $resultJSON;
The response body of my PHP backend using postman is the following string:
[ { "id": 1, "name": "Boys" }, { "id": 2, "name": "Girls" } ]
I tried json_encode for the string but I get:
"[\n {\n "id": 1,\n "name": "Boys"\n },\n {\n "id": 2,\n "name": "Girls"\n }\n]"