SlideShare uma empresa Scribd logo
1 de 45
working towards

RESTful Web Services

Friday, November 8, 13
GET /presenter/jessica
{
“name” : “Jessica Zehavi”,
“title” : “Software Engineer”,
“job” : {
“company” : “Clockwork Active Media”,
“href” : “http://www.clockwork.net”
},
“contacts” : {
“email” : “jessica@clockwork.net”,
“twitter” : “@yiska”,
“github” : “github.com/yiska”,
}
}

Friday, November 8, 13
API?

Friday, November 8, 13
standards
Friday, November 8, 13
???
Friday, November 8, 13
working towards

RESTful Web Services

Friday, November 8, 13
turns out, it’s kind of hard

Friday, November 8, 13
“A RESTful web service is an API
implemented using HTTP and
REST design principles.”
- Wikipedia (edited by me)

Friday, November 8, 13
Friday, November 8, 13
• Identification of resources

Friday, November 8, 13
• Identification of resources
• Manipulation of resources through
these representations

Friday, November 8, 13
• Identification of resources
• Manipulation of resources through
these representations

• Self-descriptive messaging

Friday, November 8, 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
Identification of Resources

Friday, November 8, 13
Identification of Resources
• Resources can be anything!

Friday, November 8, 13
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
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
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"
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
Self Descriptive Messaging

Operation

HTTP

Create

INSERT

POST

Read

SELECT

GET

Update

UPDATE

PUT

Delete

Friday, November 8, 13

Database

DELETE

DELETE
Create / POST

Create a New Project

Response

POST /projects/ HTTP/1.1

HTTP/1.1 201 Created
Content-Type: application/json

{
	
	
	
	
	
	
}

"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ]

Friday, November 8, 13

{
	
	
	
	
	
	
	
	
	
}

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ],
"created_on" : "2013-09-20",
"modified_on" : "2013-09-20"
Read / GET

Request a Resource

Response

GET /projects/1 HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json
{
	
	
	
	
	
	
	

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ],

	
	

"created_on" : "2013-09-20",
"modified_on" : "2013-09-20"

}

Friday, November 8, 13
Update / PUT

Update a Resource
PUT /projects/1 HTTP/1.1
{
	
	
}

Friday, November 8, 13

"start_date" : "2013-11-01",
"end_date" : "2014-02-28",

Response
HTTP/1.1 200 OK
Content-Type: application/json
{
	
	
	
	
	
	
	
}

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-02-28",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ]
Delete / DELETE

Delete a Resource

Response

DELETE /projects/1 HTTP/1.1

HTTP/1.1 204 No Content

Friday, November 8, 13
Hypermedia as the Engine of
Application State

?
Friday, November 8, 13
HATEOAS!
Friday, November 8, 13
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
Hypermedia!
GET /projects/1 HTTP/1.1
Response
HTTP/1.1 200 OK
Content-Type: application/json
{
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

Friday, November 8, 13

"href" : "http://www.example.com/projects/1",
"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : {
	
"href" : "http://www.example.com/deliverables",
	
"items" : [ 4, 5, 6 ]
},
"departments" : {
	
"href" : "http://www.example.com/departments",
	
"items" : [ 3, 8, 14 ]
},
"created_on" : "2013-09-20",
"modified_on" : "2013-09-20"
Common Mistakes

• Ignore hypermedia
• Using the wrong HTTP method
• Return the wrong response codes

Friday, November 8, 13
Friday, November 8, 13
NO
Friday, November 8, 13
APIs for Public Consumption

• Follow accepted standards/practices
• Consume your own API
• Versioning?

Friday, November 8, 13
Implementation

• Resources
• Relationships
• Endpoints

Friday, November 8, 13
Project Viz Application
• Tracks projects, resources and phases
• Complex and evolving requirements
• Wanted to host it themselves
• Super fast deadline!

Friday, November 8, 13
// 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
Response
HTTP/1.1 200 OK
Content-Type: application/json
{
	
	
	
	
	
	
	
	
	
}

Friday, November 8, 13

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ],
"created_on" : "2013-09-20",
"modified_on" : "2013-09-20"
// Create new project
Route::post( 'projects', function( )
{
$project = new Project( Input::get( ) );
$project->validate( );
if ( ! $project->save() )
{
App::abort( 500 );
}
return Response::json( $project, 201 );
});

Friday, November 8, 13
Response
HTTP/1.1 201 Created
Content-Type: application/json
{
	
	
	
	
	
	
	
	
	
}

Friday, November 8, 13

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2014-01-31",
"status" : "new",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ],
"created_on" : "2013-09-20",
"modified_on" : "2013-09-20"
// Update project by id
Route::put('projects/{id}', function( $id )
{
$project = Project::find( $id );
$project->fill( Input::get( ) );
$project->validate( );
if ( ! $project->save( ) )
{
App::abort( 500 );
}
return Response::json( $project );
})->where( 'id', 'd+' );

Friday, November 8, 13
Send
{ "end_date" : "2013-12-31", status : "active" }
Response
HTTP/1.1 200 OK
Content-Type: application/json
{
	
	
	
	
	
	
	
	
	
}

Friday, November 8, 13

"id" : 1,
"name" : "Museum Site Redesign",
"start_date" : "2013-10-01",
"end_date" : "2013-12-31",
"status" : "active",
"deliverables" : [ 4, 5, 6 ],
"departments" : [ 2, 8, 11 ],
"created_on" : "2013-09-20",
"modified_on" : "2013-10-26"
// Delete a project by id
Route::delete( 'projects/{id}', function( $id )
{
$project = Project::find( $id );
$project->delete( );
return Response::json( null, 204 );
})->where( 'id', 'd+' );

Response
HTTP/1.1 204 No Content

Friday, November 8, 13
Do These Things

• Try to be RESTful
• Consume your own APIs if possible
• Write Unit Tests

Friday, November 8, 13
Future!
• Rate limiting
• Authentication
• Hypermedia
• Versioning

Friday, November 8, 13
?

Friday, November 8, 13
kthxbye

Friday, November 8, 13

Mais conteúdo relacionado

Mais procurados

Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and ModernizrJussi Pohjolainen
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIScott Gardner
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
Building Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraBuilding Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraMarkus Lanthaler
 
JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsGregg Kellogg
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerRob Dodson
 
REST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practiceREST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practicehamnis
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsScott Gardner
 
Full-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with HydraFull-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with HydraMarkus Lanthaler
 

Mais procurados (17)

Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
Mobile Oslo 2012 okt
Mobile Oslo 2012 oktMobile Oslo 2012 okt
Mobile Oslo 2012 okt
 
Spout
SpoutSpout
Spout
 
Beyond the page
Beyond the pageBeyond the page
Beyond the page
 
JQuery
JQueryJQuery
JQuery
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
Etoy proyecto
Etoy proyectoEtoy proyecto
Etoy proyecto
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUI
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
Building Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraBuilding Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and Hydra
 
JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web Apps
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with Polymer
 
REST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practiceREST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practice
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the Things
 
Full-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with HydraFull-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with Hydra
 

Destaque

Dollar bersama Perfect APP!
Dollar bersama Perfect APP!Dollar bersama Perfect APP!
Dollar bersama Perfect APP!smsPerfectApp
 
The need to understand variation in healthcare population healthcare online...
The need to understand variation in healthcare   population healthcare online...The need to understand variation in healthcare   population healthcare online...
The need to understand variation in healthcare population healthcare online...rightcare
 
Apimec presentation 03-31-2009
Apimec presentation   03-31-2009Apimec presentation   03-31-2009
Apimec presentation 03-31-2009AES Tietê
 
Section 3 chapter 21 - financial management - teaching aid
Section 3   chapter 21 - financial management - teaching aidSection 3   chapter 21 - financial management - teaching aid
Section 3 chapter 21 - financial management - teaching aidAmit Fogla
 

Destaque (7)

Retail
RetailRetail
Retail
 
Dollar bersama Perfect APP!
Dollar bersama Perfect APP!Dollar bersama Perfect APP!
Dollar bersama Perfect APP!
 
The need to understand variation in healthcare population healthcare online...
The need to understand variation in healthcare   population healthcare online...The need to understand variation in healthcare   population healthcare online...
The need to understand variation in healthcare population healthcare online...
 
Apimec presentation 03-31-2009
Apimec presentation   03-31-2009Apimec presentation   03-31-2009
Apimec presentation 03-31-2009
 
Erp overview
Erp overviewErp overview
Erp overview
 
Section 3 chapter 21 - financial management - teaching aid
Section 3   chapter 21 - financial management - teaching aidSection 3   chapter 21 - financial management - teaching aid
Section 3 chapter 21 - financial management - teaching aid
 
Ppt01
Ppt01Ppt01
Ppt01
 

Semelhante a Working Towards RESTful Web Servies

Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AnglePablo Godel
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSPablo Godel
 
John Arne Sæterås - Search on Mobile
John Arne Sæterås - Search on MobileJohn Arne Sæterås - Search on Mobile
John Arne Sæterås - Search on MobileMobile Oslo
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Startedguest1af57e
 
Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)ArangoDB Database
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with GaelykChoong Ping Teo
 
BACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSBACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSDesignveloper
 
Performance & Responsive Web Design
Performance & Responsive Web DesignPerformance & Responsive Web Design
Performance & Responsive Web DesignZach Leatherman
 
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK -  Nicola Iarocci - Co...RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK -  Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...Codemotion
 
NoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationNoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationArjen Schoneveld
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearchprotofy
 
Angular directive filter and routing
Angular directive filter and routingAngular directive filter and routing
Angular directive filter and routingjagriti srivastava
 
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!Serdar Basegmez
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
SAPS - Semantic AtomPub-based Services
SAPS - Semantic AtomPub-based ServicesSAPS - Semantic AtomPub-based Services
SAPS - Semantic AtomPub-based ServicesMarkus Lanthaler
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17GreeceJS
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.jsMatthew Beale
 

Semelhante a Working Towards RESTful Web Servies (20)

Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
John Arne Sæterås - Search on Mobile
John Arne Sæterås - Search on MobileJohn Arne Sæterås - Search on Mobile
John Arne Sæterås - Search on Mobile
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
 
BACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSBACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JS
 
Performance & Responsive Web Design
Performance & Responsive Web DesignPerformance & Responsive Web Design
Performance & Responsive Web Design
 
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK -  Nicola Iarocci - Co...RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK -  Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
 
NoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationNoSQL Now 2013 Presentation
NoSQL Now 2013 Presentation
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearch
 
Angular directive filter and routing
Angular directive filter and routingAngular directive filter and routing
Angular directive filter and routing
 
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Backbone
BackboneBackbone
Backbone
 
SAPS - Semantic AtomPub-based Services
SAPS - Semantic AtomPub-based ServicesSAPS - Semantic AtomPub-based Services
SAPS - Semantic AtomPub-based Services
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
 
Google Polymer Framework
Google Polymer FrameworkGoogle Polymer Framework
Google Polymer Framework
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 

Último

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Working Towards RESTful Web Servies

  • 1. working towards RESTful Web Services Friday, November 8, 13
  • 2. GET /presenter/jessica { “name” : “Jessica Zehavi”, “title” : “Software Engineer”, “job” : { “company” : “Clockwork Active Media”, “href” : “http://www.clockwork.net” }, “contacts” : { “email” : “jessica@clockwork.net”, “twitter” : “@yiska”, “github” : “github.com/yiska”, } } Friday, November 8, 13
  • 6. working towards RESTful Web Services Friday, November 8, 13
  • 7. turns out, it’s kind of hard Friday, November 8, 13
  • 8. “A RESTful web service is an API implemented using HTTP and REST design principles.” - Wikipedia (edited by me) Friday, November 8, 13
  • 10. • Identification of resources Friday, November 8, 13
  • 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
  • 15. Identification of Resources • Resources can be anything! 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
  • 21. Create / POST Create a New Project Response POST /projects/ HTTP/1.1 HTTP/1.1 201 Created Content-Type: application/json { } "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ] Friday, November 8, 13 { } "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ], "created_on" : "2013-09-20", "modified_on" : "2013-09-20"
  • 22. Read / GET Request a Resource Response GET /projects/1 HTTP/1.1 HTTP/1.1 200 OK Content-Type: application/json { "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ], "created_on" : "2013-09-20", "modified_on" : "2013-09-20" } Friday, November 8, 13
  • 23. Update / PUT Update a Resource PUT /projects/1 HTTP/1.1 { } Friday, November 8, 13 "start_date" : "2013-11-01", "end_date" : "2014-02-28", Response HTTP/1.1 200 OK Content-Type: application/json { } "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-02-28", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ]
  • 24. Delete / DELETE Delete a Resource Response DELETE /projects/1 HTTP/1.1 HTTP/1.1 204 No Content Friday, November 8, 13
  • 25. Hypermedia as the Engine of Application State ? 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
  • 28. Hypermedia! GET /projects/1 HTTP/1.1 Response HTTP/1.1 200 OK Content-Type: application/json { } Friday, November 8, 13 "href" : "http://www.example.com/projects/1", "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : { "href" : "http://www.example.com/deliverables", "items" : [ 4, 5, 6 ] }, "departments" : { "href" : "http://www.example.com/departments", "items" : [ 3, 8, 14 ] }, "created_on" : "2013-09-20", "modified_on" : "2013-09-20"
  • 29. Common Mistakes • Ignore hypermedia • Using the wrong HTTP method • Return the wrong response codes Friday, November 8, 13
  • 32. APIs for Public Consumption • Follow accepted standards/practices • Consume your own API • Versioning? Friday, November 8, 13
  • 33. Implementation • Resources • Relationships • Endpoints 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
  • 36. Response HTTP/1.1 200 OK Content-Type: application/json { } Friday, November 8, 13 "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ], "created_on" : "2013-09-20", "modified_on" : "2013-09-20"
  • 37. // Create new project Route::post( 'projects', function( ) { $project = new Project( Input::get( ) ); $project->validate( ); if ( ! $project->save() ) { App::abort( 500 ); } return Response::json( $project, 201 ); }); Friday, November 8, 13
  • 38. Response HTTP/1.1 201 Created Content-Type: application/json { } Friday, November 8, 13 "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2014-01-31", "status" : "new", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ], "created_on" : "2013-09-20", "modified_on" : "2013-09-20"
  • 39. // Update project by id Route::put('projects/{id}', function( $id ) { $project = Project::find( $id ); $project->fill( Input::get( ) ); $project->validate( ); if ( ! $project->save( ) ) { App::abort( 500 ); } return Response::json( $project ); })->where( 'id', 'd+' ); Friday, November 8, 13
  • 40. Send { "end_date" : "2013-12-31", status : "active" } Response HTTP/1.1 200 OK Content-Type: application/json { } Friday, November 8, 13 "id" : 1, "name" : "Museum Site Redesign", "start_date" : "2013-10-01", "end_date" : "2013-12-31", "status" : "active", "deliverables" : [ 4, 5, 6 ], "departments" : [ 2, 8, 11 ], "created_on" : "2013-09-20", "modified_on" : "2013-10-26"
  • 41. // Delete a project by id Route::delete( 'projects/{id}', function( $id ) { $project = Project::find( $id ); $project->delete( ); return Response::json( null, 204 ); })->where( 'id', 'd+' ); Response HTTP/1.1 204 No Content Friday, November 8, 13
  • 42. Do These Things • Try to be RESTful • Consume your own APIs if possible • Write Unit Tests Friday, November 8, 13
  • 43. Future! • Rate limiting • Authentication • Hypermedia • Versioning Friday, November 8, 13