In this chapter, we will not cover all aspects of server-side coding, but simply summarize some basic technical elements that you should take care of.
There are several languages / Frameworks available to develop a server-side API (php, asp, node.js…), but we will focus on a simple example with php-mysql.
This exemple is very basic, the goal is to explain the basics, and the code could obviously be improved
Let’s say you want to create an API that will return the data from a MYSQL Table with customers information and allow a search on the customer country:
The first thing to do is to get the parameters sent to the API, in our example, we will just add a filter for the customer country:
Connect to the Database and execute the SQL
Loop on the results and populate an Array, and convert the result Array to JSON
Set the header for the result and return the JSON
The access-control-origin header must obviously be changed depending on your own security control check.