I’ve recently wanted to use a library, that is only available in Php (austinb/gameq)
As I really dont know much about Php, to be able to use it with my other webservices (.Net core), I’ve decided that best way would be to just host it as its own Rest service.
I’ve tried using marcj/php-rest-service but to no avail, all responses I get are 200(Ok), even when an endpoint is not correct. No errors in both browser and local consoles.
I use php -S localhost:8888 index.php
to start it. Am I missing something?
index.php
<?php include 'vendor/autoload.php'; use RestServiceServer; require_once("restGameQ.php"); Server::create('/GameQ', 'GameQRestApiGameQApi') ->collectRoutes() ->run();
restGameQ.php
<?php namespace GameQRestApi; class GameQApi { /** * Dummy response check. */ public function getHi(){ return 'Hi!'; } /** * Gets state of server defined in server.json */ public function getServersState(){ $GameQ = new GameQGameQ(); $GameQ->addServersFromFiles('servers.json'); return $GameQ->process(); } /** * Checks state of the server under this address (accepted types consult: https://github.com/Austinb/GameQ/tree/v3/src/GameQ/Protocols ) */ public function postCheckServer($type, $ip, $port){ $GameQ = new GameQGameQ(); $GameQ->addServer([ 'type' => $type, 'host' => $ip+':'+$port, ]); return $GameQ->process(); } }
P.S. I’ve really wanted to use peachpiecompiler/peachpie but they dont support yet stream_select that is required by the lib.
Advertisement
Answer
After some research, I found that marcj/php-rest-service is an old repo, with many problems in newer PHP versions.
ElementaryFramework/WaterPipe is a great, still supported and robust framework for your HTTP needs.