Contacto server API in PHP
-
Upload
hem-shrestha -
Category
Technology
-
view
500 -
download
1
description
Transcript of Contacto server API in PHP
Server side API
Hem Kr. ShresthaSemicolon Developers Network Pvt. Ltd
Email: [email protected]
Date: 5th Jan, 2013
Server-side refers to operations that are performed by the server in a client–server relationship in computer networking..
Application Program Interface
An interface by software components to communicate with each other
A set of routines, protocols, and tools for building software applications.
A good API makes it easier to develop a program by providing all the building blocks.
JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange...
Easy for machines to parse and generate
Familiar to programmers of the C-family of languages
Collection of name/value pairs
Alternative: XML
{"res": "success","data": {
"id": "1","username": "hem","c_fname": "Hem","c_lname": "Shrestha","n_home": "014488535","n_mobile": "98443096958","n_office": "014782582","created": "2012-12-21 05:52:03 pm"
}}
<?xml version="1.0" encoding="UTF-8" ?<res>success</res><data>
<id>1</id><username>hem</username><c_fname>Hem</c_fname><c_lname>Shrestha</c_lname><n_home>014488535</n_home><n_mobile>98443096958</n_mobile><n_office>014782582</n_office><created>2012-12-21 05:52:03 pm</created>
</data>
More info about JSON data http://www.json.org
But before we start
Analyze your Requirements
Note down your outputs
Add Contact
List Contact
Edit Contact
Delete Contact
Server responseSuccess, error, page not found
Required dataHere we are using JSON data format for contact information
Public function listContact () {
$sql = "SELECT * FROM `contacts` ";
$myquery = mysql_query($sql) ;
while($rows = mysql_fetch_array($myquery)){$row_array['id'] = $rows['id'];$row_array['name'] = $rows['name'];$row_array['number'] = $rows['number'];array_push($json_array,$row_array);
}
$json_result['res'] = 'success';$json_result['data'] = $json_array;echo json_encode($json_result);
}
To Add Contacthttp://katibajyo.com/api/contacto.php?action=add&username=username
&c_fname=contact_firstname&c_lname=contact_lastname&n_mobile=mobile_number&n_home=home_number&n_office=office_number
To list Contact http://katibajyo.com/api/contacto.php?action=list
To Edit Contact http://katibajyo.com/api/contacto.php?action=edit&id=contact_id
To Delete contact http://katibajyo.com/api/contacto.php?action=delete&id=contact_id
Visit http://katibajyo.com/api/contacto.php for all available operations.
JSON Object{"res": “error"
}Or{"res": "success","data": {
"id": "1","username": "hem","c_fname": "Hem","c_lname": "Shrestha","n_home": "014488535","n_mobile": "98443096958","n_office": "014782582","created": "2012-12-21 05:52:03 pm"
}}