In my previous post we were talking about how to create a REST web service. But now we want to build a client and consume this service.

The address was http://localhost/DbUsersApi.php?action=get_user_list and the result was a JSON file:

{“user_list”:[{“userid”:”D3B6F994-1DA5-47FB-8A2A-750A65AAB137″,”firstname”:”Joe”,”lastname”:”Bloggs”},{“userid”:”E19F2EC8-62B9-4C88-84DC-E0D6903177E0″,”firstname”:”John”,”lastname”:”Doe”}]}

We will use a simple HTML file with Javascript.

Consume the service with Javascript:

Create a new file in your WWW folder and name it RestJSClient.html

Load the HTML file in your browser. If you are in Chrome then click on the menu button, then More Tools and Developer Tools, then select the Console tab.

This is the result from the Console:

Javascript Console