I am creating my first API, for which, if two values ββare passed, I should get a response in JSON format. The number will be passed as POST parameters. You can use either cURL or some POST method.
Despite the fact that it is very simple, I would like to know the best practices, and the API should be created based on the controller model. Not just PHP.
I have Googled for many REST API tutorials. They were good, and I gained some knowledge about it.
But I would like to get a sample code model so that I can reference it and build my own, and this example, of course, is in the standard practice of creating a real REST API.
If you ask me what I tried, it would be a lot of fun as a beginner, all I could do was this:
$num1 = $_REQUEST['num1']; $num2 = $_REQUEST['num2']; $total = $num1 + $num2; echo json_encode($total);
Of course, this can never be called an API, but still. If I give a POST response to this, I want to get a response from the REST API as JSON. I also have to check it using the REST console to get a standard answer.
Please provide me with a very simple but still standard RESTful API.
json rest api php curl
Piya Feb 22 '14 at 19:26 2014-02-22 19:26
source share