{"id":223,"date":"2021-01-27T12:59:30","date_gmt":"2021-01-27T12:59:30","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/php\/?p=223"},"modified":"2026-10-29T01:26:18","modified_gmt":"2026-10-29T01:26:18","slug":"php-build-a-rest-api","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/","title":{"rendered":"PHP &#8211; Build a REST API"},"content":{"rendered":"<p>In this tutorial, we would learn how to build a REST API in PHP step by step. You can be sure that it&#8217;s really fun to work with PHP! So let&#8217;s do this!<\/p>\n<p>We&#8217;ll cover the following:<\/p>\n<ol>\n<li><a href=\"#t1\">Setup WAMP Server<\/a><\/li>\n<li><a href=\"#t2\">Create a Database in PHPMyadmin<\/a><\/li>\n<li><a href=\"#t3\">Write the PHP API Scripts<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Setup WAMP Server<\/strong><\/h4>\n<p>If you want to learn PHP, MySQL or both, then I would recommend you setup WAMP Server in your system. WAMP Server provides everything you need. WAMP stands for:<\/p>\n<ul>\n<li>W &#8211; Windows<\/li>\n<li>A &#8211; Apache<\/li>\n<li>M &#8211; MySQL<\/li>\n<li>P &#8211; PHP<\/li>\n<\/ul>\n<p>WAMP Server would do the following:<\/p>\n<ul>\n<li>Install and configure MySQL<\/li>\n<li>Install PHP<\/li>\n<li>Configure Apache HTTP Server<\/li>\n<\/ul>\n<p>Follow the steps below to setup WAMP Server<\/p>\n<p><strong>Step 1<\/strong> &#8211; Download WAMP Server from here &#8211; <a href=\"https:\/\/www.wampserver.com\/en\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.wampserver.com\/en\/<\/a><\/p>\n<p><strong>Step 2<\/strong> &#8211; Follow the installation steps to install WAMP server<\/p>\n<p><strong>Step 3<\/strong> &#8211; Open WAMP Server and ensure all the services starts (the icon should turn green)<\/p>\n<p><strong>Step 4<\/strong> &#8211; Open your browser and visit http:\/\/localhost:8080 and ensure that the WAMP server window displays as shown below:<\/p>\n<figure id=\"attachment_225\" aria-describedby=\"caption-attachment-225\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-225 size-large\" src=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-1024x714.jpg\" alt=\"Wamp Server Installation\" width=\"1024\" height=\"714\" srcset=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-1024x714.jpg 1024w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-300x209.jpg 300w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-768x535.jpg 768w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-120x85.jpg 120w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg 1227w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-225\" class=\"wp-caption-text\">Wamp Server Installation<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Create a Database in PHPMyAdmin<\/strong><\/h4>\n<p>We now need to create database using phpmyadmin. Then we create a table that would hold the data we want to access. So follow the steps below:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Click on the phymyadmin icon on the lower left of the windows. Then login into PHPMyadmin dashboard without any password as shown below:<\/p>\n<figure id=\"attachment_226\" aria-describedby=\"caption-attachment-226\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/PHPMyadmin-login.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-226\" src=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/PHPMyadmin-login-300x260.jpg\" alt=\"PHPMyadmin login\" width=\"300\" height=\"260\" srcset=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/PHPMyadmin-login-300x260.jpg 300w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/PHPMyadmin-login-768x666.jpg 768w, https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/PHPMyadmin-login.jpg 813w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-226\" class=\"wp-caption-text\">PHPMyadmin login<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Go ahead to create a database. I call it <strong><em>apidb<\/em><\/strong><\/p>\n<p><strong>Step 3<\/strong> &#8211; Then create a table in the database. I created a table called users with columns id, firstname, lastname.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Write the PHP API Script<\/strong><\/h4>\n<p>Now you need to write two simple scripts. This script would be placed in a folder in the root folder of the web server. The root folder of the webserver for me is D:\\wamp64\\www. So you can find where you installed WAMP.<\/p>\n<p>Then you also need some text editor: Notepad++, VSCode, Atom etc. For me I&#8217;m using VSCode.<\/p>\n<p>So follow the steps below:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create a folder inside the web root folder. I name this folder <em>restapi<\/em><\/p>\n<p><strong>Step 2<\/strong> &#8211; Create a <em>php<\/em> file that would manage connecting to the database. I name this file: <em>connect.php<\/em>. The content is shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n\r\n    <span style=\"color: #996633;\">$hostname<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"localhost\"<\/span>;\r\n    <span style=\"color: #996633;\">$username<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"root\"<\/span>;\r\n    <span style=\"color: #996633;\">$password<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\"<\/span>;\r\n    <span style=\"color: #996633;\">$dbname<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"apidb\"<\/span>;\r\n\r\n    <span style=\"color: #996633;\">$con<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #007020;\">mysqli_connect<\/span>(<span style=\"color: #996633;\">$hostname<\/span>, <span style=\"color: #996633;\">$username<\/span>, <span style=\"color: #996633;\">$password<\/span>, <span style=\"color: #996633;\">$dbname<\/span>);\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span>(<span style=\"color: #333333;\">!<\/span><span style=\"color: #996633;\">$con<\/span>){\r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span>(<span style=\"background-color: #fff0f0;\">\"Could not connect to database\"<\/span>);\r\n    }\r\n\r\n<span style=\"color: #557799;\">?&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3<\/strong> &#8211; Next create a second file in the same folder. I named it index.php. The content is<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">require_once<\/span>(<span style=\"background-color: #fff0f0;\">\"connect.php\"<\/span>);\r\n   <span style=\"color: #996633;\">$response<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">array<\/span>();\r\n\r\n    <span style=\"color: #996633;\">$sql<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"select * from users\"<\/span>;\r\n    <span style=\"color: #996633;\">$result<\/span> <span style=\"color: #333333;\">=<\/span> mysqli_query(<span style=\"color: #996633;\">$con<\/span>,<span style=\"color: #996633;\">$sql<\/span>);\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span>(<span style=\"color: #996633;\">$result<\/span>){\r\n        <span style=\"color: #996633;\">$i<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n        <span style=\"color: #888888;\">\/\/Loop through the results<\/span>\r\n        <span style=\"color: #008800; font-weight: bold;\">while<\/span>(<span style=\"color: #996633;\">$row<\/span> <span style=\"color: #333333;\">=<\/span> mysqli_fetch_assoc(<span style=\"color: #996633;\">$result<\/span>)){\r\n            <span style=\"color: #996633;\">$response<\/span>[<span style=\"color: #996633;\">$i<\/span>][<span style=\"background-color: #fff0f0;\">'id'<\/span>] <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$row<\/span>[<span style=\"background-color: #fff0f0;\">'id'<\/span>];\r\n            <span style=\"color: #996633;\">$response<\/span>[<span style=\"color: #996633;\">$i<\/span>][<span style=\"background-color: #fff0f0;\">'firstname'<\/span>] <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$row<\/span>[<span style=\"background-color: #fff0f0;\">'firstname'<\/span>];\r\n            <span style=\"color: #996633;\">$response<\/span>[<span style=\"color: #996633;\">$i<\/span>][<span style=\"background-color: #fff0f0;\">'lastname'<\/span>] <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$row<\/span>[<span style=\"background-color: #fff0f0;\">'lastname'<\/span>]; \r\n            <span style=\"color: #996633;\">$i<\/span><span style=\"color: #333333;\">++<\/span>;           \r\n        }\r\n        <span style=\"color: #888888;\">\/\/Encode the response in JSON format<\/span>\r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> <span style=\"color: #007020;\">json_encode<\/span>(<span style=\"color: #996633;\">$response<\/span>);\r\n    }\r\n\r\n<span style=\"color: #557799;\">?&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>At this point, save both file and visit the url in the browser http:\/\/localhost:8080\/restapi\/index<\/p>\n<p>The list of names in the database would displayed as shown below as json<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">[{<span style=\"color: #007700;\">\"id\"<\/span>:<span style=\"background-color: #fff0f0;\">\"1\"<\/span>,<span style=\"color: #007700;\">\"firstname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Kindson\"<\/span>,<span style=\"color: #007700;\">\"lastname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Munonye\"<\/span>},\r\n{<span style=\"color: #007700;\">\"id\"<\/span>:<span style=\"background-color: #fff0f0;\">\"2\"<\/span>,<span style=\"color: #007700;\">\"firstname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Lyudmila\"<\/span>,<span style=\"color: #007700;\">\"lastname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Nagones\"<\/span>},\r\n{<span style=\"color: #007700;\">\"id\"<\/span>:<span style=\"background-color: #fff0f0;\">\"3\"<\/span>,<span style=\"color: #007700;\">\"firstname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Saffron\"<\/span>,<span style=\"color: #007700;\">\"lastname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Lawrence\"<\/span>},\r\n{<span style=\"color: #007700;\">\"id\"<\/span>:<span style=\"background-color: #fff0f0;\">\"4\"<\/span>,<span style=\"color: #007700;\">\"firstname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Othniel\"<\/span>,<span style=\"color: #007700;\">\"lastname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Ndubuisi\"<\/span>},\r\n{<span style=\"color: #007700;\">\"id\"<\/span>:<span style=\"background-color: #fff0f0;\">\"5\"<\/span>,<span style=\"color: #007700;\">\"firstname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Othniel\"<\/span>,<span style=\"color: #007700;\">\"lastname\"<\/span>:<span style=\"background-color: #fff0f0;\">\"Ndubuisi\"<\/span>}]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we would learn how to build a REST API in PHP step by step. You can be sure that it&#8217;s really fun &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[37],"tags":[40,39,38],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-rest-api","tag-apache","tag-mysql","tag-wamp-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP - Build a REST API | Kindson The Genius<\/title>\n<meta name=\"description\" content=\"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP - Build a REST API | Kindson The Genius\" \/>\n<meta property=\"og:description\" content=\"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-27T12:59:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-29T01:26:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1227\" \/>\n\t<meta property=\"og:image:height\" content=\"855\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\"},\"headline\":\"PHP &#8211; Build a REST API\",\"datePublished\":\"2021-01-27T12:59:30+00:00\",\"dateModified\":\"2026-10-29T01:26:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/\"},\"wordCount\":460,\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Wamp-Server-1024x714.jpg\",\"keywords\":[\"Apache\",\"MySQL\",\"WAMP Server\"],\"articleSection\":[\"REST API\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/\",\"name\":\"PHP - Build a REST API | Kindson The Genius\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Wamp-Server-1024x714.jpg\",\"datePublished\":\"2021-01-27T12:59:30+00:00\",\"dateModified\":\"2026-10-29T01:26:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\"},\"description\":\"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Wamp-Server.jpg\",\"contentUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Wamp-Server.jpg\",\"width\":1227,\"height\":855,\"caption\":\"Wamp Server Installation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-build-a-rest-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP &#8211; Build a REST API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/\",\"name\":\"PHP Tutorial\",\"description\":\"Beginner to Expert With Practicals\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP - Build a REST API | Kindson The Genius","description":"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/","og_locale":"en_US","og_type":"article","og_title":"PHP - Build a REST API | Kindson The Genius","og_description":"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","og_url":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/","og_site_name":"PHP Tutorial","article_published_time":"2021-01-27T12:59:30+00:00","article_modified_time":"2026-10-29T01:26:18+00:00","og_image":[{"width":1227,"height":855,"url":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#article","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60"},"headline":"PHP &#8211; Build a REST API","datePublished":"2021-01-27T12:59:30+00:00","dateModified":"2026-10-29T01:26:18+00:00","mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/"},"wordCount":460,"image":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-1024x714.jpg","keywords":["Apache","MySQL","WAMP Server"],"articleSection":["REST API"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/","url":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/","name":"PHP - Build a REST API | Kindson The Genius","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/php\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#primaryimage"},"image":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server-1024x714.jpg","datePublished":"2021-01-27T12:59:30+00:00","dateModified":"2026-10-29T01:26:18+00:00","author":{"@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60"},"description":"PHP - Build a REST API \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#primaryimage","url":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg","contentUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2021\/01\/Wamp-Server.jpg","width":1227,"height":855,"caption":"Wamp Server Installation"},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/php\/php-build-a-rest-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/php\/"},{"@type":"ListItem","position":2,"name":"PHP &#8211; Build a REST API"}]},{"@type":"WebSite","@id":"https:\/\/kindsonthegenius.com\/php\/#website","url":"https:\/\/kindsonthegenius.com\/php\/","name":"PHP Tutorial","description":"Beginner to Expert With Practicals","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kindsonthegenius.com\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/kindsonthegenius.com\/php\/author\/kindsonthegenius-3\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/223\/revisions\/228"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}