62. 62
Engine.IO - Overview
● Ensure the most reliable realtime communication
● Always establishes a long-polling connection first
63. 63
Engine.IO - Overview
● Ensure the most reliable realtime communication
● Always establishes a long-polling connection first
– then tries to upgrade to better transports that are
"tested" on the side
65. 65
Engine.IO - Upgrade transport seamlessly
● Switches from polling to another transport in
between polling cycles
66. 66
Engine.IO - Upgrade transport seamlessly
● Switches from polling to another transport in
between polling cycles
● To ensure no messages are lost, the upgrade packet
will only be sent once all the buffers of the existing
transport are flushed and the transport is
considered paused
77. 77
Why we don't use WebSocket
● Server
– Many corporate proxies block WebSocket traffic
● Client
– Many personal firewalls and antivirus softwares block
WebSocket traffic
83. 83
When unsafe APIs done - Server
1.Store affected devices' ID & API ID to database
2.Send Push to affected devices
84. 84
When unsafe APIs done - Client
● Send an unified GET request
– GET /datas
85. 85
When unsafe APIs done - Client
● Send an unified GET request
– GET /datas
● Push off
– apply frequency rapidly to achieve realtime, but waste
resources
86. 86
When unsafe APIs done - Client
● Send an unified GET request
– GET /datas
● Push off
– apply frequency rapidly to achieve realtime, but waste
resources
● Push on
– apply frequency long to save resources
– when Push comes, send request to get newest data to
achieve realtime
99. 99
RESTful API Design
● HTTP method
● Common examples
● Is Graph API RESTful?
● Actual example
● Internal & Open API
100. 100
GET - Retrieve a resource
● A request to the server should never change the
resource state
101. 101
GET - Retrieve a resource
● A request to the server should never change the
resource state
● Incidental side effects are OK
– Like logging
102. 102
GET - Retrieve a resource
● A request to the server should never change the
resource state
● Incidental side effects are OK
– Like logging
● Common response code
– 200 OK
103. 103
GET - Retrieve a resource
● A request to the server should never change the
resource state
● Incidental side effects are OK
– Like logging
● Common response code
– 200 OK
– 301 Moved Permanently
104. 104
GET - Retrieve a resource
● A request to the server should never change the
resource state
● Incidental side effects are OK
– Like logging
● Common response code
– 200 OK
– 301 Moved Permanently
– 404 Not Found (related to DELETE)
– 410 Gone (related to DELETE)
105. 105
DELETE - Remove a resource
● A request to the server should destroy the
resource & never refer to it again
106. 106
DELETE - Remove a resource
● A request to the server should destroy the
resource & never refer to it again
● Common response code
– 200 OK
– 202 Accepted
– 204 No Content
112. 112
POST-to-append
● A request to the server should create a new
resource
● Common response code
– 201 Created (plus "Location" header)
113. 113
POST-to-append
● A request to the server should create a new
resource
● Common response code
– 201 Created (plus "Location" header)
– 202 Accepted
115. 115
Overloaded POST
● Providing a block of data, such as the result of
submitting a form, to a data-handling process
● "Data-handling process" can be anything
116. 116
Overloaded POST
● Providing a block of data, such as the result of
submitting a form, to a data-handling process
● "Data-handling process" can be anything
– POST /users/sort
117. 117
Overloaded POST
● Providing a block of data, such as the result of
submitting a form, to a data-handling process
● "Data-handling process" can be anything
– POST /users/sort
– POST /login
118. 118
Overloaded POST
● Providing a block of data, such as the result of
submitting a form, to a data-handling process
● "Data-handling process" can be anything
– POST /users/sort
– POST /login
– ...etc.
119. 119
PUT - Update a resource
● A request to the server should modify the resource
120. 120
PUT - Update a resource
● A request to the server should modify the resource
● Common response code
– 200 OK
– 204 No Content
141. Graph API - Overview
● Everything is a "node" has a unique ID
142. 142
Graph API - Overview
● Everything is a "node" has a unique ID
● Two nodes connect each other with a "edge"
143. 143
Graph API - Overview
● Everything is a "node" has a unique ID
● Two nodes connect each other with a "edge"
● A node information contains some "fields"
144. 144
Graph API - Are two people friends?
● GET /{user-a-id}/friends/{user-b-id}
145. 145
Graph API - Does someone like a Page?
● GET /{user-id}/likes/{page-id}
146. 146
Graph API - Publishing new Status Updates
● POST /{user-id}/feed
● POST /{page-id}/feed
147. 147
Graph API - Uploading Photos
● POST /{user-id}/photos
● POST /{page-id}/photos
● POST /{album-id}/photos
168. 168
Internal API design guideline
● Minimize data size
● Merge operations
● Field names are short & convoluted
169. 169
Internal API design guideline
● Minimize data size
● Merge operations
● Field names are short & convoluted
● Customize request & response for official apps
186. 186
References
●
Browser 與 Server 持續同步的作法介紹
● Comet (programming)
● Engine.IO: the realtime engine
● Engine.IO Protocol
● API Design Optimized for Mobile Platform
● HTTP GET with request body
● Does Google treat 404 and 410 status code differen
tly