SlideShare una empresa de Scribd logo
RESTful 4 all 
Diego Sapriza 
diego@sapriza.net 
@AV4TAr
Como diseñar una API RESTful 
sin morir en el intento.
Hi!I’M 
Diego Sapriza 
@AV4TAr
RESTful Para todos by Diego Sapriza
PHP.meetup.uy 
DevOps.meetup.uy 
. 
.uy
“El mundo evoluciona 
constantemente”
Restful api 
versionamiento 
recursos 
status codes 
autenticación 
mensajes 
paginación 
documentación! 
hypermedia (HATEOAS) 
verbos 
tools
Quiénes hacen 
mayoritariamente 
Web dev?
REpresentational State transfer 
no es un estándar
Acuerdo 
https://www.flickr.com/photos/124247024@N07/
RESTful Para todos by Diego Sapriza
Roy Fielding 
escalabilidad 
:(
restricciones escalabilidad 
Client-Server 
Stateless 
Cache 
Uniform Interfaces 
Layered System 
Code on demand (opcional)
Richardson Maturity Model 
http://bit.ly/api-rmm
0: The Swamp of POX 
RPC 
SOBRE 
HTTP
JSON 
XML 
html 
images
0: The Swamp of POX 
GET 
http://srv.com/addin/auto-­‐harvest/end-­‐job/:id/ 
errors/:errors_messages 
http://srv.com/addin/auto-­‐harvest/start-­‐job/:id
Richardson Maturity Model 
http://bit.ly/api-rmm
Uniform Interfaces 
• Identificación recursos. 
• Manipulación de recursos a través de su 
representación. 
• Mensajes auto-descriptivos. 
• Hypermedia como motor del estado de la 
aplicación (HATEOAS).
1: RECURSOS 
tienen una URI 
mapean entidad/es 
sustantivos
uri 
scheme:hierarchical part[?query][#fragment] 
telnet://192.168.1.1 
urn:isbn:978-1-449-3150-9 
mailto:diego@sapriza.net 
https://api.twilio.com/2010-­‐04-­‐01
identificación 
/recurso/:id 
/recurso/:id/:acción 
! 
/?r=recurso&id=:id 
/?r=recurso&id=:id&a=:acción
colecciones 
/recursos 
/recursos/:id 
/recursos/:id?pagina=:n&limite=100
Richardson Maturity Model
Uniform Interfaces 
• Identificación recursos. 
• Manipulación de recursos a través de su 
representación.! 
• Mensajes auto-descriptivos. 
• Hypermedia como motor del estado de la 
aplicación (HATEOAS).
Representación
HTTP verbs 
Get Post Put Delete 
Patch Options Head 
Trace Connect 
http://bit.ly/http-­‐request-­‐methods
crud http 
CREATE POST 
READ GET 
UPDATE PUT 
DELETE DELETE
método seguro idempotente cachable 
GET 
HEAD 
POST 
PUT 
DELETE
GET /personas Obtener 
lista 
de 
personas 
POST /personas Agregar 
una 
persona 
DELETE /personas/:id Eliminar 
una 
persona 
GET /personas/:id Obtener 
una 
persona 
PUT /personas/:id Actualizar 
una 
persona 
GET /personas/:id/contactos Obtener 
los 
contactos 
de 
una 
persona 
POST /personas/:id/contactos Agregar 
un 
contacto 
a 
una 
persona 
POST /personas/subirImagen Subir 
una 
imagen
y ahora… 
¿qué hacemos con estos msjs?
Richardson Maturity Model
Documentar…
Uniform Interfaces 
• Identificación recursos. 
• Manipulación de recursos a través de su 
representación. 
• Mensajes auto-descriptivos.! 
• Hypermedia como motor del estado de la 
aplicación (HATEOAS).
auto-descriptivos 
¿Cómo procesar el mensaje? 
¿qué parser utilizar? 
¿Caching?
ahora… 
¿cómo son los mensajes? 
HAL Collection JSON Siren
HTTP/1.1 200 OK! 
Content-Type: application/json! 
{! 
"status":"ok",! 
"message":"Data retrieved OK!",! 
"data" : [! 
!{! 
!! "id": 90, ! 
!! "modelId": 81, ! 
!! "path": "Somewhere over the rainbow.rvt"! 
!},! 
!{! 
!! "id": 91, ! 
!! "modelId": 13, ! 
!! "path": "Blue birds fly.rvt”! 
}]! 
}! 
GET 
http://server/addin/auto-­‐harvest/get-­‐jobs/ o_O
HTTP/1.1 200 OK! 
Content-Type: application/json! 
{! 
"status":"error",! 
"message":"Page not found”,! 
"data" : []! 
}! 
o_O
status codes 
2xx - Success 
3xx - Redirection 
4xx - Client Error 
5xx - Server Error
Error messages 
api-problem 
HTTP/1.1 401 Unauthorized! 
Content-Type: application/problem+json! 
{! 
! "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",! 
! "title": "Unauthorized",! 
! "status": 401,! 
! "detail": "Unauthorized",! 
! "authentication_uri": "/oauth"! 
}!
Uniform Interfaces 
• Identificación recursos. 
• Manipulación de recursos a través de su 
representación. 
• Mensajes auto-descriptivos. 
• Hypermedia como motor del estado de la 
aplicación (HATEOAS).
HATEOAS 
Clients make state transitions only through 
actions that are dynamically identified 
within hypermedia by the server. ! 
Except for simple fixed entry points to the 
application, a client does not assume that 
any particular action is available for any 
particular resources beyond those 
described in representations previously 
received from the server.
clase.php 
public class Customer! 
{! 
! ! public $Id;! 
! ! public $Name;! 
}!
clase.c# 
public class Customer! 
{! 
! public int Id { get; set; }! 
! public string Name { get; set; }! 
}!
json 
{ ! 
"id" : "1"! 
"name" : "Diego"! 
}!
HAL 
http://bit.ly/hal-spec 
{! 
"id": "diego",! 
"name": "Diego Sapriza”,! 
! 
"_links": {! 
"self": {! 
"href": "http://web.org/api/user/diego"! 
},! 
"website": {! 
"href": "http://web.org/api/locations/diego"! 
}! 
}! 
} !
HAL 
{! 
.. *snip* ..! 
"_embedded": {! 
"website": {! 
"_links": {! 
"self": {! 
"href": “http://web.org/api/locations/diego"! 
}! 
},! 
"id": "diego",! 
"url": "http://diego.uy"! 
}! 
}! 
}!
HAL - colecciones 
{! 
"_links": {! 
"self" :{ "href": "http://web.org/api/user?page=3" },! 
"first":{ "href": "http://web.org/api/user" },! 
"prev" :{ "href": "http://web.org/api/user?page=2" },! 
"next" :{ "href": "http://web.org/api/user?page=4" },! 
"last" :{ "href": "http://web.org/api/user?page=133" }! 
},! 
"count": 3,! 
"total": 498,! 
...! 
}
https://api.github.com
{! 
"current_user_url": "https://api.github.com/user",! 
"authorizations_url": "https://api.github.com/authorizations",! 
"emails_url": "https://api.github.com/user/emails",! 
"emojis_url": "https://api.github.com/emojis",! 
"events_url": "https://api.github.com/events",! 
"feeds_url": "https://api.github.com/feeds",! 
"following_url": "https://api.github.com/user/following{/target}",! 
"gists_url": "https://api.github.com/gists{/gist_id}",! 
"hub_url": "https://api.github.com/hub",! 
"issues_url": "https://api.github.com/issues",! 
"keys_url": "https://api.github.com/user/keys",! 
"notifications_url": "https://api.github.com/notifications",! 
"organization_url": "https://api.github.com/orgs/{org}",! 
"public_gists_url": "https://api.github.com/gists/public",! 
"rate_limit_url": "https://api.github.com/rate_limit",! 
"repository_url": "https://api.github.com/repos/{owner}/{repo}",! 
"starred_url": "https://api.github.com/user/starred{/owner}{/repo}",! 
"starred_gists_url": "https://api.github.com/gists/starred",! 
"team_url": "https://api.github.com/teams",! 
"user_url": "https://api.github.com/users/{user}",! 
"user_organizations_url": "https://api.github.com/user/orgs",! 
...! 
}!
Richardson Maturity Model 
http://bit.ly/api-rmm
Sigamos links
Restful api 
versionamiento! 
recursos 
status codes 
autenticación! 
mensajes 
paginación 
documentación! 
hypermedia (HATEOAS) 
verbos 
tools
Versiona tu API
HTTP 
GET 
https://web.com/api/v1/users/diego
HTTP 
GET 
https://web.com/api/users/diego 
api-­‐version: 
2
HTTP 
GET 
https://web.com/api/users/diego 
Accept: 
application/vnd.myapi.v2+json
HTTP 
GET 
https://web.com/api/users/diego 
por defecto última versión 
Headers para versiones anteriores
autenticación
crea tu propio método
HTTP Basic Auth 
! 
HTTP Digest 
! 
OAuth2
tools 
Postman 
Runscope 
jsonmate.com
Restful api 
versionamiento 
recursos 
status codes 
autenticación 
mensajes 
paginación 
documentación! 
hypermedia (HATEOAS) 
verbos 
tools
RESTful Para todos by Diego Sapriza
@AV4TAr 
http://AV4TAr.com 
https://speakerdeck.com/av4tar/restful-para-todos
RESTful Para todos by Diego Sapriza
• http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong- 
which-is.html 
• http://martinfowler.com/articles/ 
richardsonMaturityModel.html 
• http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful- 
api 
• http://spf13.com/post/soap-vs-rest 
• https://leanpub.com/build-apis-you-wont-hate 
• https://speakerdeck.com/caseysoftware/on-the-edge-of-hypermedia- 
midwest-dot-io

Más contenido relacionado

PDF
PDF
WORKSHOP I: Introducción a API REST
PDF
Introducción a las API's Rest
PDF
Rest Conf Rails
PDF
BPM with REST
PDF
REST - deSymfony2012
WORKSHOP I: Introducción a API REST
Introducción a las API's Rest
Rest Conf Rails
BPM with REST
REST - deSymfony2012

Similar a RESTful Para todos by Diego Sapriza (20)

PPTX
Desarrollando con APIs
PDF
Servicios REST - PucelaTechDay
PPTX
Taller definición de apis
PPTX
Define y desarrolla tu primera api
PPTX
Tecnologias Web Semantica
PPTX
Api rest ful
PDF
APIs REST #devfestBilbao
PPTX
Fundamentos para el diseño de una RESTful API pragmática
PPTX
Arquitectura de la Web y Computación en el Servidor
PDF
T final modulo_1
PPTX
Introducción a REST - SymfonyVLC
ODP
Web framework ligeros y micros en java barcamp 2014
ODP
Desarrollando un API con REST
ODP
Documertar APIs - Meetup.js
PDF
ASR_Tema_3.pdf
PDF
Web services restful con JAX-RS
PDF
Servicios Rest con Jersey
PDF
Postman.pdf
PDF
Paper ieee
PDF
Api rest client en Android
Desarrollando con APIs
Servicios REST - PucelaTechDay
Taller definición de apis
Define y desarrolla tu primera api
Tecnologias Web Semantica
Api rest ful
APIs REST #devfestBilbao
Fundamentos para el diseño de una RESTful API pragmática
Arquitectura de la Web y Computación en el Servidor
T final modulo_1
Introducción a REST - SymfonyVLC
Web framework ligeros y micros en java barcamp 2014
Desarrollando un API con REST
Documertar APIs - Meetup.js
ASR_Tema_3.pdf
Web services restful con JAX-RS
Servicios Rest con Jersey
Postman.pdf
Paper ieee
Api rest client en Android
Publicidad

Más de .NET Conf UY (18)

PPTX
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
PDF
Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...
PPTX
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
PPTX
Building Modern Websites with ASP.NET by Rachel Appel
PPTX
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
PPTX
Windows y .NET en la Internet of Things by Pablo Garcia
PPTX
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
PPTX
Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...
PDF
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
PDF
Emprendiendo un futuro by Gabriel Camargo
PPTX
Microsoft Platform Vision by Eduardo Mangarelli
PDF
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
PPTX
Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...
PDF
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
PPTX
Opportunities to Improve System Reliability and Resilience by Donald Belcham
PPTX
Introduction to Aspect Oriented Programming by Donald Belcham
PPTX
Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan Fernandez
PPTX
Azure: un parque de diversiones en la nube para el desarrollador moderno by A...
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Modern Websites with ASP.NET by Rachel Appel
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
Windows y .NET en la Internet of Things by Pablo Garcia
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Emprendiendo un futuro by Gabriel Camargo
Microsoft Platform Vision by Eduardo Mangarelli
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Opportunities to Improve System Reliability and Resilience by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham
Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan Fernandez
Azure: un parque de diversiones en la nube para el desarrollador moderno by A...
Publicidad

Último (20)

DOCX
Guía 5. Test de orientación Vocacional 2.docx
PPTX
Historia Inteligencia Artificial Ana Romero.pptx
DOCX
TRABAJO GRUPAL (5) (1).docxjsjsjskskksksk
DOCX
TRABAJO GRUPAL (5) (1).docxsjjsjsksksksksk
PPTX
ANCASH-CRITERIOS DE EVALUACIÓN-FORMA-10-10 (2).pptx
PPTX
sa-cs-82-powerpoint-hardware-y-software_ver_4.pptx
PPTX
Diapositivas Borrador Rocha Jauregui David Paolo (3).pptx
PDF
MANUAL TECNOLOGÍA SER MINISTERIO EDUCACIÓN
PDF
CyberOps Associate - Cisco Networking Academy
PDF
Tips de Seguridad para evitar clonar sus claves del portal bancario.pdf
PDF
TRABAJO DE TECNOLOGIA.pdf...........................
PDF
CONTABILIDAD Y TRIBUTACION, EJERCICIO PRACTICO
DOCX
Trabajo grupal.docxjsjsjsksjsjsskksjsjsjsj
PDF
MANUAL de recursos humanos para ODOO.pdf
PDF
capacitación de aire acondicionado Bgh r 410
PPTX
ccna: redes de nat ipv4 stharlling cande
PPTX
la-historia-de-la-medicina Edna Silva.pptx
PDF
PRESENTACIÓN GENERAL MIPIG - MODELO INTEGRADO DE PLANEACIÓN
PDF
informe_fichas1y2_corregido.docx (2) (1).pdf
PDF
Diapositiva proyecto de vida, materia catedra
Guía 5. Test de orientación Vocacional 2.docx
Historia Inteligencia Artificial Ana Romero.pptx
TRABAJO GRUPAL (5) (1).docxjsjsjskskksksk
TRABAJO GRUPAL (5) (1).docxsjjsjsksksksksk
ANCASH-CRITERIOS DE EVALUACIÓN-FORMA-10-10 (2).pptx
sa-cs-82-powerpoint-hardware-y-software_ver_4.pptx
Diapositivas Borrador Rocha Jauregui David Paolo (3).pptx
MANUAL TECNOLOGÍA SER MINISTERIO EDUCACIÓN
CyberOps Associate - Cisco Networking Academy
Tips de Seguridad para evitar clonar sus claves del portal bancario.pdf
TRABAJO DE TECNOLOGIA.pdf...........................
CONTABILIDAD Y TRIBUTACION, EJERCICIO PRACTICO
Trabajo grupal.docxjsjsjsksjsjsskksjsjsjsj
MANUAL de recursos humanos para ODOO.pdf
capacitación de aire acondicionado Bgh r 410
ccna: redes de nat ipv4 stharlling cande
la-historia-de-la-medicina Edna Silva.pptx
PRESENTACIÓN GENERAL MIPIG - MODELO INTEGRADO DE PLANEACIÓN
informe_fichas1y2_corregido.docx (2) (1).pdf
Diapositiva proyecto de vida, materia catedra

RESTful Para todos by Diego Sapriza