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);
    exit(0);

} 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

1 comment:

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

Post a Comment