How can i fetch only single row data from REST API?

Hey guys, I’m trying to make news web application and build my own rest api. I built my api and when i checked from postman, the requests are working fine. I created two endpoints : http://localhost/api/v1/news for all data, http://localhost/api/v1/news/{id} for single data. When i request these endpoint it outputs a json array and works correctly. So in my index.php file, i wanted to show all news title and posters and i can fetch from the first endpoint with file_get_contents() and json_decode() methods. Here is my codes in index.php file for fetch all data from api:

        $id = urlencode("id");
        $data = json_decode(file_get_contents("http://localhost/api/v1/news/"),true);
        

        foreach($data as $result){
            echo '<a href="newsDetails.php?id='.$result['id'].'"><h3>'.$result['title'].'</h3></a>
            <img src="'.$result['poster_link'].'" width = "800px" height= "600px" alt="" srcset="">
            <br><br><br>
            ';

        }

it works fine. Also i will share my news.php file for creating my api:

<?php
	include("../config.php");
	$db = new Db();
	$connection =  $db->getConnstring();

	$request_method=$_SERVER["REQUEST_METHOD"];

    switch($request_method)
	{
		case 'GET':
			// Retrive News
			if(!empty($_GET["id"]))
			{
				$id=intval($_GET["id"]);
				get_thenew($id);
			}
			else
			{
				get_news();
			}
			break;
		default:
			// Invalid Request Method
			header("HTTP/1.0 405 Method Not Allowed");
			break;

        case 'POST':
            // Insert News
            add_news();
            break; 
            
        case 'PUT':
            // Update News
            $id=intval($_GET["id"]);
            update_news($id);
            break;   

        case 'DELETE':
            // Delete News
            $id=intval($_GET["id"]);
            delete_news($id);
            break;   
	}

    function get_news()
	{
		global $connection;
		$query="SELECT * FROM tb_news";
		$response=array();
		$result=mysqli_query($connection, $query);
		while($row=mysqli_fetch_assoc($result))
		{
			$response[]=$row;
		}
		header('Content-Type: application/json');
		echo json_encode($response);
	}

    function get_thenew($id=0)
{
	global $connection;
	$query="SELECT * FROM tb_news";
	if($id != 0)
	{
		$query.=" WHERE id='".$id."'";
	}
	$response=array();
	$result=mysqli_query($connection, $query);
	while($row=mysqli_fetch_assoc($result))
	{
		$response[]=$row;
	}
	header('Content-Type: application/json');
	echo json_encode($response);
}

function add_news()
	{
		global $connection;

		$data = json_decode(file_get_contents('php://input'), true);
		$title=$data["title"];
		$details=$data["details"];
		$poster_link = $data["poster_link"];
		echo $query="INSERT INTO tb_news SET title='".$title."', details='".$details."',poster_link='.$poster_link.'";
		if(mysqli_query($connection, $query))
		{
			$response=array(
				'status' => 1,
				'status_message' =>'News Added Successfully.'
			);
		}
		else
		{
			$response=array(
				'status' => 0,
				'status_message' =>'News Addition Failed.'
			);
		}
		header('Content-Type: application/json');
		echo json_encode($response);
	}

    function update_news($id)
	{
		global $connection;
		$post_vars = json_decode(file_get_contents("php://input"),true);
		$title=$post_vars["title"];
		$details=$post_vars["details"];
		$poster_link = $post_vars["poster_link"];
		$query="UPDATE tb_news SET title='".$title."', details='".$details."', poster_link=''.$poster_link.'' WHERE id=".$id;
		if(mysqli_query($connection, $query))
		{
			$response=array(
				'status' => 1,
				'status_message' =>'News Updated Successfully.'
			);
		}
		else
		{
			$response=array(
				'status' => 0,
				'status_message' =>'News Updation Failed.'
			);
		}
		header('Content-Type: application/json');
		echo json_encode($response);
	}

    function delete_news($id)
{
	global $connection;
	$query="DELETE FROM tb_news WHERE id=".$id;
	if(mysqli_query($connection, $query))
	{
		$response=array(
			'status' => 1,
			'status_message' =>'News Deleted Successfully.'
		);
	}
	else
	{
		$response=array(
			'status' => 0,
			'status_message' =>'News Deletion Failed.'
		);
	}
	header('Content-Type: application/json');
	echo json_encode($response);
}
?>

But i want to make another php file called newsDetails.php because when i click the news from the index.php file, i want to see details of the news in newsDetails.php?id=any_number. But it gives an error called Warning: Undefined array key "id" in C:\xampp\htdocs\api\newsDetails.php on line 43.
Also i will share my newsDetails.php codes where it gives an error:

<?php 
     
        $id = urlencode($_GET["id"]);
        $data = json_decode(file_get_contents("http://localhost/api/v1/news/$id"),true);
        
            echo '<title>'.$data['title'].'</title>';

    ?>

So i get an error on the first row as you can see i am trying to use get request but it doesn’t work. How can i fix this issue? How can i fetch single row data from my api?