Contacto server API in PHP

13
Server side API Hem Kr. Shrestha Semicolon Developers Network Pvt. Ltd Email: [email protected] Date: 5 th Jan, 2013

description

Contacto is the application developed in the "Startup Bootcamp" organized by GDG Kathmandu and Mobile Nepal. This event was focused on the android app development for storing the contact information online through the interface of API. And this presentation is the part of this event to describe the Serverside API Development and the resulting JSON Data format.

Transcript of Contacto server API in PHP

Page 1: Contacto server API in PHP

Server side API

Hem Kr. ShresthaSemicolon Developers Network Pvt. Ltd

Email: [email protected]

Date: 5th Jan, 2013

Page 2: Contacto server API in PHP

Server-side refers to operations that are performed by the server in a client–server relationship in computer networking..

Page 3: Contacto server API in PHP

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.

Page 4: Contacto server API in PHP

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

Page 5: Contacto server API in PHP

{"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

Page 6: Contacto server API in PHP

But before we start

Analyze your Requirements

Note down your outputs

Page 7: Contacto server API in PHP

Add Contact

List Contact

Edit Contact

Delete Contact

Page 8: Contacto server API in PHP

Server responseSuccess, error, page not found

Required dataHere we are using JSON data format for contact information

Page 9: Contacto server API in PHP

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);

}

Page 10: Contacto server API in PHP

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.

Page 11: Contacto server API in PHP

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"

}}

Page 12: Contacto server API in PHP
Page 13: Contacto server API in PHP