September 2017
Intermediate to advanced
244 pages
6h 44m
English
Till now, we are done with most of the common code. So let's look at blog post endpoints. In blog post endpoints, the first one is the blog posts listing.
Blog posts listing endpoints:
So, let's replace the previous code in posts.php with the proper code to serve posts. And to serve this, put the following code in the posts.php file:
<?php$url = $_SERVER['REQUEST_URI'];// checking if slash is first character in route otherwise add itif(strpos($url,"/") !== 0){ $url = "/$url";}if($url == '/posts' && $_SERVER['REQUEST_METHOD'] == 'GET') { $posts = getAllPosts(); echo json_encode($posts);}function getAllPosts() { return [ [ 'id' => 1, 'title' => 'First Post', 'content' => 'It is all ...
Read now
Unlock full access