11. • Identification of resources
• Manipulation of resources through
these representations
Friday, November 8, 13
12. • Identification of resources
• Manipulation of resources through
these representations
• Self-descriptive messaging
Friday, November 8, 13
13. • Identification of resources
• Manipulation of resources through
these representations
• Self-descriptive messaging
• Hypermedia as the engine of
application state (HATEOAS)
Friday, November 8, 13
16. Identification of Resources
• Resources can be anything!
• URLs identify resources
http://www.example.com/projects/
http://www.example.com/projects/1
http://www.example.com/deliverables/42
Friday, November 8, 13
17. Identification of Resources
• Resources can be anything!
• URLs identify resources
http://www.example.com/projects/
http://www.example.com/projects/1
http://www.example.com/deliverables/42
• The representation describes the
resource’s state
Friday, November 8, 13
18. Manipulation of Resources through
Representations
Project Represented in JSON
{
}
Friday, November 8, 13
"id" : 1,
"name" : "Focus Media Group Project",
"start_date" : "2013-01-01",
"end_date" : "2014-06-31",
"status" : "complete",
"deliverables" : [ 1, 2, 3 ],
"departments" : [ 3, 8, 14 ],
"created_on" : "2013-09-20"
"modified_on" : "2013-10-01"
19. Manipulation of Resources through
Representations
Project Represented in XML
<?xml version="1.0" encoding="UTF-8"?>
<project>
<id>1</id>
<name>Focus Media Group Project</name>
<start_date>2013-01-01</start_date>
<end_date>2013-01-01</end_date>
<status>complete</status>
<deliverables>
<item>1</item>
<item>2</item>
<item>3</item>
</deliverables>
<departments>
<item>1</item>
<item>2</item>
<item>3</item>
</departments>
<created_on>2013-09-20</created_on>
<modified_on>2013-10-01</modified_on>
</project>
Friday, November 8, 13
27. You Know This
“The principle of connectedness: each web page
tells you how to get to the adjoining pages. The
Web as a whole works on the principle of
connectedness, which is better known as
‘hypermedia as the engine of application state,’
sometimes abbreviated HATEOAS.”
- Leonard Richardson & Mike Amundsen
RESTful Web APIs
Friday, November 8, 13
34. Project Viz Application
• Tracks projects, resources and phases
• Complex and evolving requirements
• Wanted to host it themselves
• Super fast deadline!
Friday, November 8, 13
35. // Get all projects
Route::get( 'projects', function( )
{
$projects
= Project::all( );
return Response::json( $projects );
});
// Get a project by id
Route::get( 'projects/{id}', function( $id )
{
$project = Project::find( $id );
if ( ! $project ) {
App::abort( 404 );
}
return Response::json( $project );
} )->where( 'id', 'd+' );
Friday, November 8, 13