A system for creating a URL based API to a dataset?
I would like to create a web service where by I allow users to query a dataset (hosted on some server) through a URL.
A user would use a URL like:
In order to get the data.
What is the simplest (free, open-source) system to setup for creating such a service? (PHP+MySQL is probably preferred)
$year_start = $_GET['yearstart']; $year_end = $_GET['yearend']; $data_type = $_GET['datatype']; $topic = "" $_GET['topic']; /* here fetch return value from db, file system, intergalatic source, divine logic.. */ $return = "fetched from above"; echo json_encode($return);
NOTE: remember to escape all data that you get from the URL/any other source of user input before acting on it
UPDATE: Basically what you will need to do is something like:
- Fetch all the parameters required by your web service (In your case it will come through the URL)
- Sanitize/Validate the parameters (If there are errors, show it immediately and terminate)
- Once you are sure all the data passed to the service is good, act upon it (Usually this means some DB queries/calculations etc)
- After the action step is done, prepare the data in a format that is understandable to the web service client (For starters, I would assume just XML or JSON, later on you could try advanced protocols like SOAP - remember SOAP is just XML, in a standard that supports the SOAP protocol, that's all)
- I have added a link below which shows a simple example of generating XML/JSON as a web service response (It is difficult to explain the whole thing in this answer)
- Once you have the response ready, echo it out to the web service client.
Check out this link which shows a basic and easy example of creating a simple web service using PHP/MySQL: