Tuesday 9 August 2016

how to create REST API in php

Simple three Step create Rest API 

STEP->1 create config.php

STEP-> 2create api.php

STEP-> 3create class.api.php


config.php

$host ='localhost';
$username ='root';
$password ='';
$db = 'db';

$con = mysqli_connect($host,$username,$password,$db);
if(mysqli_error($con))
{
printf("Connect failed %s\n",mysqli_connect_error());
exit();

}

api.php

require_once('config.php');
require_once('class.api.php');


$obj = new Fanu();

switch ($_REQUEST['method']){

case 'login':
  $obj->login();
  break;

default:
  $msg = array('message'=>'Some data is missing please try again after sometime !!!');
  print(json_encode($msg));



};

class.api.php

require_once('config.php');

class Fanu {

/*For login */
         /*
* Code for login api.
* Perameters: uname, password are required.
*/


public function login(){
                                              -------code here

     }

    }

No comments:

Post a Comment