How to Expose and Route to a Resource?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Program – How to Expose and Route to a Resource? If you want to provide access to resource and handle according to the HTTP method check code below.

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Solution

The Solution is $_SERVER[‘REQUEST_METHOD’].

<?php

$request = explode('/', $_SERVER[PATH_INFO]);
$method = strtolower($_SERVER['REQUEST_METHOD']);

switch($method){
    case 'get':
        //for handling GET Request
        Break;
    case 'post':
        //for handling POST Request
        Break;
    case 'put'
        //for handling PUT Request
        Break;
    case 'delete':
        //for handling DELETE Request
        Break;
    default:
        //unimplemented method
    http_response_code(405);
}

इसे भी पढ़े – Call Flipkart API with PHP Code Example

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *