How To Build A Web Service
-
Upload
moses-ngone -
Category
Technology
-
view
581 -
download
2
description
Transcript of How To Build A Web Service
HOW {TO}BUILD A WEB SERVICE
1
Sunday, October 9, 11
OVERVIEWI. REST API
II. DATA FORMATS - (JSON vs XML)
III. Request
IV. Response
2
Sunday, October 9, 11
NEED TO KNOWI. HTTP
I. Methods
II. Headers
III. Status Codes
3
Sunday, October 9, 11
HOW TOI. Troubleshooting
II. Tools
III. PHP Frameworks
4
Sunday, October 9, 11
REST
5
/*** Representational State Transfer*/
Sunday, October 9, 11
6
/*** Representational State Transfer*/
- use HTTP methods to determine action.
- use HTTP headers identify specifics of the request and how to handle the response
Sunday, October 9, 11
7
/*** USEFUL HTTP METHODS*/
- GET: retrieve resource representation (read*)
- POST: create* new resource
- PUT: update* resource
- DELETE*
Sunday, October 9, 11
8
/*** USEFUL HTTP HEADERS*/
- Accept and Content-Type: used for content format negotiation
- User-Agent: Identify what made the request
Sunday, October 9, 11
9
/*** HTTP STATUS CODES*/
- 200: OK
- 301: Moved
- 302: Found
- 401: Not Authorized
- 403: Forbidden
- 404: Not Found
- 500: Server Error
- Custom *
Sunday, October 9, 11
DATA FORMATS
10
/** * JSON vs XML */
Sunday, October 9, 11
11
/*** JSON: JavaScript Object Notation*/
Pros
- Comes standard in PHP
- Light
- Great for devices
Sunday, October 9, 11
12
/*** JSON: JavaScript Object Notation*/
Cons
- Hard to distinguish Object vs Array in php
- Not as descriptive
Sunday, October 9, 11
13
/** * XML*/
Pros
- Verbose and Precise
- Great for Machine to Machine
- Inherent style depending on the client.
Sunday, October 9, 11
14
/*** XML*/
Cons
- Heavy
- Multiple PHP libraries / parsers
- Multiple standard formats (plain, rss, atom etc)
Sunday, October 9, 11
15
/** * Request and Respond */
- Resource are always in pluralhttp://api.local.ws/users/1
- When no identifier is present, the collection is the resourcehttp://api.local.ws/users
- Respond with appropriate status code
Sunday, October 9, 11
16
/** * Tools */
- Apigee
- YQL
- Charles
- Browser (GET, POST)
- Packet Sniffers
- PHP (curl,file_get_contents)
- any http client*
- RESTClient
Sunday, October 9, 11
DO IT17
Sunday, October 9, 11
MOSES NGONE@mosesngone
http://mospired.com
18
THANK YOUSunday, October 9, 11