Oct 11, 2016

How to write RESTful APIs in "Vanilla" PHP?

PHP supports them native. In a certain PHP, I have to code in "pure PHP", no RESTful APIs library/engine provided. So I decided to write a file called api.php to handle all API request. I used this pattern
if ($grabber->method() === 'GET') {
    // define your APIs here
    echo json_encode(array('Appl RESTful APIs'), JSON_UNESCAPED_UNICODE);

} else if ($grabber->method() === 'POST') {
    // define your APIs here

} else if ($grabber->method() === 'PUT') {
    // define your APIs here

} else if ($grabber->method() === 'DELETE') {
    // define your APIs here

You can see the api.php at Github


Kamalesh Kumar said...

Great post !! Nice and effective blog post. The content is too short but effective. I love the information you share here. Its an well written blog post by you. This is awesome blog post. Visit this best resume writing service, if you are looking for any writing related help

raghu konda said...

Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.more 
php jobs in hyderabad.

Post a Comment