These following instructions will show you how to correctly consume this RESTFUL API for use in the SOFT332 module.
Backend
This web service uses the http commands GET, POST, PUT and DELETE to show and manipulate data on this URL:
http://msmithies.byethost22.com/restInterface/
The SQL database and table are hard coded into the PHP scripts for ease of consumption.
There is a three tiered approach to this restful service that combines client elements with processing then finally database manipulation.
Client side : data you input for the RESTFUL api.
Server side intermediary : data inputed is formatted as JSON notation.
Serverside : JSON data is used to manipulate the database then return the results.
The field in the table are as follows:
id (Primary Key)
name
job
GET
In order to view data that is required the primary key field must be used in the url to retrieve a specific row.
To retrieve all of the rows in the api use the 'getid' command at the end of the URL
example
'http://msmithies.byethost22.com/restInterface/getid'
This will retrieve all rows in the table encoded as JSON format. You can use the individual 5 digit id numbers to return individual rows. It is recommended that this is used before using 5 digit numerical id.
example
'http://msmithies.byethost22.com/restInterface/10001'
No credentials are required for using GET as the REST service acts initially as read only. Checks are conducted to see whether the id is correct, these are not returned as JSON, but a comment appears warning that the id isn't recognised.
Client Side Manipulation
The next three http commands essentially use the same style of execution.
A client has to be made to hold the values of authentication as well as the input for the rows for the database.
Authentication
The two elements essentially required for access for the database is the username and password.
Username: blah
Password: blah
They will have to be combined within the curl data when the request is sent and they will have to be used for every instance of a POST, PUT or DELETE response.
Inorder to successfully manipulate the database the type names of each piece of data will have to match.
Use these type names:
Username - username of the database, listed above
Password - password of the database, listed above
Request - request you wish to perform (POST, PUT or DELETE)
Id - id of the person(row) in the database table
Name - name of the person(row) in the database table
Job - job of the person(row) in the database table
A number of these elements will have to be used depending on the HTTP request you require, details of data will be noted in the respective request section.
The elements should be combined in a query string before the data is posted.
example pseudocode
$query_string = "Username=".$username."&";
$query_string .= "Password=".$password."&";
$query_string .= "Request=".$request."&";
$query_string .= "Id=".$id."&";
etc.
Below is an example of the curl attributes that are strongly recommended that you use when data is HTTP posted.
example pseudocode
<?php
$url="http://msmithies.byethost22.com/restInterface/index.php";
//remember to concatenate the different parts of data strings from forms
$query_string_data="Username=b22_10289976&Password=frogger0&Request=POST&Id=10005&Name=Batman&Job=Ice creams"
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query_string_data);
curl_exec ($curl);
curl_close ($curl);
?>
POST
POST data requires the authentication of the database. A POST response to insert a new record with the Name and Job of the person(row). The Id is automatically incremented so any Id added to this query will be ignored.
PUT
PUT data requires the authentication of the database. A PUT response to update a record with the Id, Name and Job of the person(row).
DELETE
PUT data requires the authentication of the database. A DELETE response to delete a record with the unique Id of the person(row).
No comments:
Post a Comment