This solution is built using PHP, with PHP's APCU extension allowing the state of the deck to be maintained between requests.
Copy server.php and the Classes folder to a web-accessible location on a PHP-enabled server with the APCU extension installed.
A functioning copy of the service may be tested via http://172.233.131.65/client.php. Client.php serves as a GUI that's creating calls to server.php, which resides in the same directory. Your own script should be able to communicate with http://172.233.131.65/server.php as well, for as long as the demo is active.
The file client.php contains examples of usage, written in PHP and Javascript.
All requests to the API are performed by POSTing to URL where server.php resides (i.e. https://your-server.com/cards/server.php).
POST request must contain a variable 'cmd ', which may take on the following values:
| 'cmd' | extra POST vars needed | response | description |
| deal | json-encoded value-pairs suite and type, i.e. {"suit":"spades","type":"4"} | deals the top card from the deck | |
| shuffle | shuffles the deck | ||
| discard | an array with the following properties: suite and type, indicating the card to be discarded | discards a previously dealt card | cut | a variable "index", whose value indicates the card that the deck will be cut at | "cuts" the deck (all cards below this number will be placed above all cards currently above this number, in the same relative order) |
| order | orders the deck in a default sorting order (spades > clubs > hearts > diamonds, 2 - A). Discards are unaffected. | ||
| rebuild | orders the deck in a default sorting order (spades > clubs > hearts > diamonds, 2 - A). Discards are added back into the deck. | ||
| reset | orders the deck in a default sorting order (spades > clubs > hearts > diamonds, 2 - A). Discards and all dealt cards are added back into the deck. | ||
| cheat | json-encoded value-pairs for the suit and type of the card currently at the top of the deck (i.e., "{"suit":"spades","type":"4"}") | take a peek at the next card |
Response code of 200 indicates a successful request. Response code of 406 indicates an error with the request. A descriptive message will usually be provided in case of 406 responses.