SlideShare a Scribd company logo
PHP TRONG PHÁT TRIỂN
   MOBILE WEB SERVICE
Hanoi – PHP Day 2011
Ngô Xuân Lộc
CNC Mobile - Android Technical Leader
NỘI DUNG

Web Services?
Các chuẩn Web Services
Nguyên tắc thiết kế Web Services theo chuẩn RESTful
Tạo một Web Service đơn giản theo chuẩn RESTful bằng
PHP
WEB SERVICES ?

“Web Services are frequently just Web APIs that can be accessed over a
network, such as the Internet, and executed on a remote system hosting the
requested services” - WikiPedia -
Php day 2011 cnc ph ptrongphattrien mobile
CÁC CHUẨN WEB SERVICES

XML – RPC (remote procedure call)
SOAP (Simple Object Access Protocol)
RESTful (Representational State Transfer)
CÁC CHUẨN WEB SERVICES

XML – RPC

Ra đời vào năm 1998

là một giao thức gọi thủ tục từ xa (RPC) trong đó sử

dụng XML để mã hóa dữ liệu và sủ dụng các giao thức

HTTP để truyền tải
SOAP

Có thể coi là một protocol giống như HTTP-Get, và
HTTP-Post
SOAP dựa trên nền tảng XML.
SOAP là một chuẩn Web Services dựa trên chức
năng
Một application có thể request một dịch vụ (web
service) thông qua các SOAP envelop và nhận kết
RESTful
Giới thiệu lần đầu vào năm 2000
Là một chuẩn Web Service hướng đến tài nguyên
và dễ dàng sử dụng để thực thi và cung cấp dịch
vụ
Sử dụng các phương thức HTTP
Php day 2011 cnc ph ptrongphattrien mobile
So sánh tốc độ Download và thực thi Web Service theo hai
            chuẩn SOAP và RESTful (login api)
THIẾT KẾ WS THEO RESTful

        Phương pháp truy xuất chỉ dựa trên POST, GET
[GET/POST]
server/api/user/adduser?name=username&email=email@mail.com
[GET]
server/api/user/userdetail?name=username&email=email2@mail.com
[GET/POST]
server/api/user/updateuser?name=username&email=email2@mail.com
[GET] server/api/user/deleteuser?name=username
THIẾT KẾ WS THEO RESTful

Các phương thức truy xuất dữ liệu
POST




 POST /api/feeds/ HTTP 1.1
 HOST : https://go.urbanairship.com
 Content-Type: application/json
 { "feed_url": "http://example.com/atom.xml", "template": { "aps": {
 "badge": 1, "sound": "cat.caf", "alert": "New item from some place! {{ title
 }}" } }, "broadcast": true }
GET



 GET /api/feeds/ HTTP 1.1
 HOST : https://go.urbanairship.com
 Content-Type: application/json




 GET /api/push/stats/?start=<timestamp>&end=<timestamp> HTTP 1.1
 HOST : https://go.urbanairship.com
 Content-Type: application/json
PUT



 PUT /api/apids/<apid> HTTP/1.1
 Host:   https://go.urbanairship.com
 Content-Type: application/json
 { "alias": "example_alias", "tags": ["tag1", "tag2"] }




 PUT /api/device_tokens/<token>/ HTTP 1.1
 HOST : https://go.urbanairship.com
 Content-Type: application/json
 {"alias": "myalias"}
DELETE



 DELETE to /api/apids/<apid>
 HOST : https://go.urbanairship.com
 Content-Type: application/json
RESTful TRONG PHP

Các thành phần chính trong xây dựng RESTful web service
The URL (required)
The Method – GET, POST, PUT, or DELETE (required)
The Agruments (required)
Credentials (opt)
The Response Body
The Response Status Code
Other Response Info (opt)
Php day 2011 cnc ph ptrongphattrien mobile
Php day 2011 cnc ph ptrongphattrien mobile
Php day 2011 cnc ph ptrongphattrien mobile
Php day 2011 cnc ph ptrongphattrien mobile
TÀI LIỆU THAM KHẢO

http://blog.garethj.com/2009/02/17/building-a-restful-web-application-
with-php/
http://www.gen-x-design.com/archives/making-restful-requests-in-php/
http://www.ibm.com/developerworks/vn/edu/ws-understand-web-
services1/section2.html
http://www.ibm.com/developerworks/vn/library/ws-restful/
THANKS YOU

    Q&A

More Related Content

PPTX
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
PDF
04 web optimization
PDF
Mobilemonday.vn mobile interaction - mr ng cuu long goldsun focus media
PDF
Xdebug from a to x
PDF
04. Web optimization
PDF
Javascript for php developer
PPT
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
PDF
Consistent Hashingの小ネタ
GIỚI THIỆU CÁC DẠNG MÁY CHỦ SERVER
04 web optimization
Mobilemonday.vn mobile interaction - mr ng cuu long goldsun focus media
Xdebug from a to x
04. Web optimization
Javascript for php developer
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Consistent Hashingの小ネタ

Similar to Php day 2011 cnc ph ptrongphattrien mobile (20)

PPT
PDF
Web server là gì? Cách thức hoạt động và các loại máy chủ web phổ biến
PPTX
Giới thiệu WCF
PDF
41060-Article Text-130234-1-10-20190706.pdf
PDF
BÀI 7 Triển khai, hướng phát triển cho web mobile - Giáo trình FPT
PPT
Ung dun web chuong 2
PPTX
REST API Introduction for training on jobs.pptx
PDF
03 udpt php
PPTX
Bản cuối
PDF
Dsd05 02a-xml-rpca
PPTX
07 web course 2 php truyen nhan du lieu
PPTX
07 web course 1 php co ban
PDF
Bai 4 lap trình phia client
PDF
Bài 4: Thao tác với dữ liệu SharePoint thông qua ADO.NET Data Services và REST
PDF
Bài thuyết trình môn công nghệ web
PDF
Slide android application and rest service 0503
PPT
Slide Web Service
PDF
9 application layer
PDF
Technical note playframework_documentation_working with play - java_vn
PPTX
Tìm hiểu web service
Web server là gì? Cách thức hoạt động và các loại máy chủ web phổ biến
Giới thiệu WCF
41060-Article Text-130234-1-10-20190706.pdf
BÀI 7 Triển khai, hướng phát triển cho web mobile - Giáo trình FPT
Ung dun web chuong 2
REST API Introduction for training on jobs.pptx
03 udpt php
Bản cuối
Dsd05 02a-xml-rpca
07 web course 2 php truyen nhan du lieu
07 web course 1 php co ban
Bai 4 lap trình phia client
Bài 4: Thao tác với dữ liệu SharePoint thông qua ADO.NET Data Services và REST
Bài thuyết trình môn công nghệ web
Slide android application and rest service 0503
Slide Web Service
9 application layer
Technical note playframework_documentation_working with play - java_vn
Tìm hiểu web service
Ad

More from Quang Anh Le (20)

PPTX
Mobilemonday.vn adflex
PPTX
Mobilemonday.vn momo-monetize thinking_tu do tai chinh_v1.2
PDF
02 mobile monday hanoi april 2013 vinova
PPT
01 mobile monday hanoi april 2013 mobile game - afoli
PPTX
03 mobile monday hanoi april 2013 monetize thinking g mo m-work
PPT
2. minh chau momo t4
PPT
0. mobilemonday.vn hcm 20130424
PPT
Vietnam mobile day 2012 phan mem cho phai dep - mana
PPTX
Vietnam mobile day 2012 i os memory management - techmaster
PPTX
Vietnam mobile day 2012 monetizing mobile apps games - rubycell
PDF
Vietnam mobile day 2012 cuoc cach mang thoi ky hau mobile - misfit
PPTX
Vietnam mobile day 2012 multi platform development - game loft
PDF
Vietnam mobile day 2012 developer opportunity - nokia
PPT
Vietnam mobile day 2012 building a mobile linux firmware for your router - ...
PPT
Vietnam mobile day 2012 ban quyen mobile contents - vsm
PDF
Vietnam mobile day 2012 platform mo va ung dung de phat trien mang xa hoi m...
PPT
Vietnam mobile day 2012 co hoi mobile tai vietnam - cyber agent
PPTX
Vietnam mobile day 2012 html5 game using impact js - aiti-aptech
PPTX
Vietnam mobile day 2012 tuong lai cho nha phat trien nds - share plus
PPSX
Vietnam mobile day 2012 trends in mobile marketing - fifth i media
Mobilemonday.vn adflex
Mobilemonday.vn momo-monetize thinking_tu do tai chinh_v1.2
02 mobile monday hanoi april 2013 vinova
01 mobile monday hanoi april 2013 mobile game - afoli
03 mobile monday hanoi april 2013 monetize thinking g mo m-work
2. minh chau momo t4
0. mobilemonday.vn hcm 20130424
Vietnam mobile day 2012 phan mem cho phai dep - mana
Vietnam mobile day 2012 i os memory management - techmaster
Vietnam mobile day 2012 monetizing mobile apps games - rubycell
Vietnam mobile day 2012 cuoc cach mang thoi ky hau mobile - misfit
Vietnam mobile day 2012 multi platform development - game loft
Vietnam mobile day 2012 developer opportunity - nokia
Vietnam mobile day 2012 building a mobile linux firmware for your router - ...
Vietnam mobile day 2012 ban quyen mobile contents - vsm
Vietnam mobile day 2012 platform mo va ung dung de phat trien mang xa hoi m...
Vietnam mobile day 2012 co hoi mobile tai vietnam - cyber agent
Vietnam mobile day 2012 html5 game using impact js - aiti-aptech
Vietnam mobile day 2012 tuong lai cho nha phat trien nds - share plus
Vietnam mobile day 2012 trends in mobile marketing - fifth i media
Ad

Php day 2011 cnc ph ptrongphattrien mobile

  • 1. PHP TRONG PHÁT TRIỂN MOBILE WEB SERVICE Hanoi – PHP Day 2011 Ngô Xuân Lộc CNC Mobile - Android Technical Leader
  • 2. NỘI DUNG Web Services? Các chuẩn Web Services Nguyên tắc thiết kế Web Services theo chuẩn RESTful Tạo một Web Service đơn giản theo chuẩn RESTful bằng PHP
  • 3. WEB SERVICES ? “Web Services are frequently just Web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services” - WikiPedia -
  • 5. CÁC CHUẨN WEB SERVICES XML – RPC (remote procedure call) SOAP (Simple Object Access Protocol) RESTful (Representational State Transfer)
  • 6. CÁC CHUẨN WEB SERVICES XML – RPC Ra đời vào năm 1998 là một giao thức gọi thủ tục từ xa (RPC) trong đó sử dụng XML để mã hóa dữ liệu và sủ dụng các giao thức HTTP để truyền tải
  • 7. SOAP Có thể coi là một protocol giống như HTTP-Get, và HTTP-Post SOAP dựa trên nền tảng XML. SOAP là một chuẩn Web Services dựa trên chức năng Một application có thể request một dịch vụ (web service) thông qua các SOAP envelop và nhận kết
  • 8. RESTful Giới thiệu lần đầu vào năm 2000 Là một chuẩn Web Service hướng đến tài nguyên và dễ dàng sử dụng để thực thi và cung cấp dịch vụ Sử dụng các phương thức HTTP
  • 10. So sánh tốc độ Download và thực thi Web Service theo hai chuẩn SOAP và RESTful (login api)
  • 11. THIẾT KẾ WS THEO RESTful Phương pháp truy xuất chỉ dựa trên POST, GET [GET/POST] server/api/user/adduser?name=username&email=email@mail.com [GET] server/api/user/userdetail?name=username&email=email2@mail.com [GET/POST] server/api/user/updateuser?name=username&email=email2@mail.com [GET] server/api/user/deleteuser?name=username
  • 12. THIẾT KẾ WS THEO RESTful Các phương thức truy xuất dữ liệu
  • 13. POST POST /api/feeds/ HTTP 1.1 HOST : https://go.urbanairship.com Content-Type: application/json { "feed_url": "http://example.com/atom.xml", "template": { "aps": { "badge": 1, "sound": "cat.caf", "alert": "New item from some place! {{ title }}" } }, "broadcast": true }
  • 14. GET GET /api/feeds/ HTTP 1.1 HOST : https://go.urbanairship.com Content-Type: application/json GET /api/push/stats/?start=<timestamp>&end=<timestamp> HTTP 1.1 HOST : https://go.urbanairship.com Content-Type: application/json
  • 15. PUT PUT /api/apids/<apid> HTTP/1.1 Host: https://go.urbanairship.com Content-Type: application/json { "alias": "example_alias", "tags": ["tag1", "tag2"] } PUT /api/device_tokens/<token>/ HTTP 1.1 HOST : https://go.urbanairship.com Content-Type: application/json {"alias": "myalias"}
  • 16. DELETE DELETE to /api/apids/<apid> HOST : https://go.urbanairship.com Content-Type: application/json
  • 17. RESTful TRONG PHP Các thành phần chính trong xây dựng RESTful web service The URL (required) The Method – GET, POST, PUT, or DELETE (required) The Agruments (required) Credentials (opt) The Response Body The Response Status Code Other Response Info (opt)
  • 22. TÀI LIỆU THAM KHẢO http://blog.garethj.com/2009/02/17/building-a-restful-web-application- with-php/ http://www.gen-x-design.com/archives/making-restful-requests-in-php/ http://www.ibm.com/developerworks/vn/edu/ws-understand-web- services1/section2.html http://www.ibm.com/developerworks/vn/library/ws-restful/
  • 23. THANKS YOU Q&A