Application architecture for the rest of us - php xperts devcon 2012
Rest in Good! - DevCon 2017
-
Upload
andre-goliath -
Category
Technology
-
view
58 -
download
1
Transcript of Rest in Good! - DevCon 2017
REST is an abbreviation for…
a) Really Strange Topic
b) Relational Enterprise Scheme Trade
c) Representational State Transfer
d) ??? [use “send a comment”]
Use PUT to create or replace resources
if you know their exact URL
Otherwise, POST to the parent resource
Use PUT to replace a whole resource at once,
PUT operations must be idempotent!
Use PATCH to update partial data
We have a list of items, e.g. /messages
How do we get the number of all messages?
a) GET /messages and {…count: 5…}
b) GET /messages/count
c) GET /messages?count
d) ??? [use “send a comment”]
We have a list of items, e.g. /messages
How do we get the number of all messages?
> HEAD /messages
< …
< X-COUNT: 5
We GET the current temperature from
/house/livingroom/temp. But the sensor is
kinda unstable and needs to be power-cycled
from time to time. How would you do it?
a) POST /house/livingroom/temp/reset
b) PUT /house/livingroom/temp/reset
c) DELETE /house/livingroom/temp
d) ??? [use “send a comment”]
We GET the current temperature from
/house/livingroom/temp. But the sensor is
kinda unstable and needs to be power-cycled
from time to time. How would you do it?
> POST /house/scheduledTasks
> {
> time: ‘now’,
> action: ‘reset’,
> target: ‘livingroom/temp’
> }
> POST /house/scheduledTasks
> {
> time: ‘in 2 hours’,
> action: ‘reset’,
> target: ‘livingroom/temp’
> }
> POST /house/scheduledTasks
> {
> time: ‘in 2 hours’,
> action: ‘reset’,
> target: ‘livingroom/temp’
> }
< HTTP/1.1 201 Created
< Location: https://…/scheduledTasks/7dhe9u
< HTTP/1.1 201 Created
< Location: https://…/scheduledTasks/7dhe9u
> GET /house/scheduledTasks/7dhe9u
< Cache-Control "max-age=3600, must-revalidate"
< {
< time: ‘2017-11-10T13:15:28+02:00’,
< action: ‘reset’,
< target: ‘livingroom/temp’,
< status: ‘scheduled’
< }
> GET /house/scheduledTasks/7dhe9u
< {
< time: ‘2017-11-10T13:15:32+02:00’,
< action: ‘reset’,
< target: ‘livingroom/temp’,
< status: ‘done’,
< result: 200
< }
> GET /house/scheduledTasks/7dhe9u
< ???
a) 404 – Not Found
b) 202 - Accepted
c) 204 – No Content
d) 410 – Gone
e) ??? [use “send a comment”]
> GET /house/scheduledTasks/7dhe9u
< HTTP/1.1 410 Gone
> GET /house/scheduledTasks/1234567890
< HTTP/1.1 404 Not Found
Why 404 has no ‘double meaning’
> GET /house/scheduledTasks/1234567890
< HTTP/1.1 404 Not Found
> GET /house/scheduledTasks/7dhe9u
< HTTP/1.1 410 Gone
> GET /house/scheduledTasks/8fks3k
< HTTP/1.1 200 OK
> GET /house/scheduledTasks/9edm4d
< HTTP/1.1 200 OK
Why 404 has no ‘double meaning’
> GET /houes/scheduledTasks/1234567890
< HTTP/1.1 404 Not Found
> GET /houes/scheduledTasks/7dhe9u
< HTTP/1.1 404 Not Found
> GET /houes/scheduledTasks/8fks3k
< HTTP/1.1 404 Not Found
> GET /houes/scheduledTasks/9edm4d
< HTTP/1.1 404 Not Found
Hypertext as the Engine of Application State
(HATEOAS)
https://github.com/farrelmr/introtospringdatarest