我已经在postman中测试过很多REST API,但是从来没有遇到过包含$_REQUEST['method']的API,它决定调用什么方法。现在我的问题是如何在邮递员上测试这个API。如何在邮递员中传递$_REQUEST['method']名字。
这是我的PHP代码
include_once('config.php');
if(isset($_REQUEST['method'])){
// echo '
';
if($_POST['method']=='create'){
$name= $_POST['name'];
$location = $_POST['location'];
// $images = null;
$rating = $_POST['rating'];
$specility = $_POST['specility'];
$file = rand(1000,100000)."-".time().'-'.$_FILES['image']['name'];
$file_loc = $_FILES['image']['tmp_name'];
$file_size = $_FILES['image']['size'];
$file_type = $_FILES['image']['type'];
$path_name="images/".$file;
move_uploaded_file($file_loc,$path_name);
$query = "INSERT into `restaurant` (name, location, image, rating,specility) VALUES ('$name', '$location', '$path_name', '$rating','$specility')";
$result = mysqli_query($con,$query);
if($result){
echo json_encode(['status'=>'success','response'=>'Restaurant created successfuly']);
}else{
echo json_encode(['status'=>'failed','response'=>'Restaurant details are not proper']);
}
}
if($_POST['method']=='list'){
$query = "SELECT * FROM `restaurant`";
$result = mysqli_query($con,$query);
if(mysqli_num_rows($result)>0){
$data=mysqli_fetch_assoc($result);
echo json_encode(['status'=>'success','response'=>$data]);
}else{
echo json_encode(['status'=>'failed','response'=>'No data found']);
}
}
}else{
echo json_encode(['status'=>'failed','response'=>'Something went wrong']);
}
我还在服务器上托管了这个API。我不知道我在互联网上搜索什么来解决这个问题。请看下面的图片,出于安全考虑,我更改了网址。
请告诉我我该怎么做。