How to write a REST API?
Just to let you know:
I ended up using Ruby on Rails.
EDIT: Since this answer has been downvoted for not providing the reason behind choosing Ruby on Rails and also no instructions on how to write a REST API with it, I thought I would give you my motivation and some simple instructions.
I started reading a book about Ruby on Rails and realized that all I needed to do was to use scaffolding and I got a JSON REST API for free.
Here's a good guide to get you started: http://guides.rubyonrails.org/getting_started.html
When you have your Ruby on Rails environment up and running, creating your REST API isn't harder than running:
$ rails generate scaffold Post name:string title:string content:text
(Example from the above link.) I also found that Rails is very easy and free to deploy to heroku, which meant that I didn't have to pay for hosting for my very basic, low traffic, REST API. There are many other reasons why I am very happy to work with Ruby on Rails, but that's beyond the context of this question.
How to add a REST API to the Modern Web Dev Server?
You could write a plugin for it but I wouldn't recommend it.
It's a development server designed for testing client-side code.
It isn't designed to be a production server, and if you are going to write a REST API then you will, presumably, want it to be usable in a production environment.
Build your API with a tool designed for it (such as Express.js or Spring Boot) and use CORS to make it accessible to the server you use for client-side development.
Related Topics
How to Fix the Permission Error When I Call Session_Start()
How to Access Dynamic Variable Names in Twig
MySQLi_Fetch_Array While Loop Columns
String With Array Structure to Array
"Vertical" Regex Matching in an Ascii "Image"
Is There Any Particular Difference Between Intval and Casting to Int - '(Int) X'
Using Default Arguments in a Function
What Is the Syntax For Accessing PHP Object Properties
What Does MySQL_Real_Escape_String() Do That Addslashes() Doesn'T
Print_R() Adds Properties to Datetime Objects
How Exactly Do Regular Expression Word Boundaries Work in PHP
How to Extract a Node Attribute from Xml Using PHP'S Dom Parser
PHP Domdocument Errors/Warnings on Html5-Tags