SlideShare a Scribd company logo
1 of 35
Service approach for
development Rest API in
Symfony2
Aleksey Kryvtsov @ Web-developer at CPCS
alkryvtsov@gmail.com
REST
REpresentational State Transfer
PART 1
HISTORY
REST was defined by Roy Thomas Fielding in 2000
In his dissertation "Architectural Styles and the Design of
Network - based Software Architectures"
3
● Client - server
● Stateless
● Cacheable
● Layered system
● Uniform interface:
○ Identification of resources
○ Manipulation of resources through these representations
○ Self-descriptive messages
○ Hypermedia as the engine of application state (HATEOAS)
ARCHITECTURAL CONSTRAINTS
4
CLIENT - SERVER | STATELESS
5
CACHEABLE
Unsafe methods
Safe methods
GET /articles/1234 HTTP/1.1 - example of safe method
PUT /articles/1234 HTTP/1.1 - example of unsafe method
6
CACHING PROCESS
GET /articles/1234 HTTP/1.1
- The resource is not cached yet
- Send request to the API
- Store response in cache and return
GET /articles/1234 HTTP/1.1
- The resource is cached
- Return response from cache
PUT /articles/1234 HTTP/1.1
- Unsafe method, send to API
PURGE /articles/1234 HTTP/1.1
- API sends PURGE method to the
cache
- The resources is removed from the
cache
GET /articles/1234 HTTP/1.1
- The resource is not cached yet
- Send request to the API
- Store response in cache and return
7
LAYERED SYSTEM
GET /article/1234 HTTP/1.1
8
Identification of resources
GET /article/1234 HTTP/1.1
9
Manipulation of resources through these representations
{"Title": "Your title", "Text": "Your text"}
{"id": 1, "Title": "Your title", "Text": "Your text"}
JSON
POST /articles HTTP/1.1
10
11
Self-descriptive messages
Request:
GET /articles/1234 HTTP/1.1
Host: test.host.com
User-Agent: Mozilla/5.0
Accept: application/json
Connection: close
(empty line)
11
Server Response:
HTTP/1.1 200 OK
Date: Wed, 16 Mar 2016 11:20:59 GMT
Server: Apache
Content-Language: ru
Content-Type: application/json;
charset=utf-8
Content-Length: 1234
Connection: close
(empty line)
(json representation)
BENEFITS
● Reliability
● Performance
● Scalability
● Simplicity
● Portability
● Modifiability
● Visibility
12
REST design maturity levels
(Richardson Maturity Model)
13
/index.php?controller=page&action=getarticleid=5
/article/5/4/6/size/media/image?page=2
Level 0
Cacheable ? Scalable ? Readable ? Simplicity ?
Modifiability ? Visibility ?
14
GET /articles HTTP/1.1
We want all articles
GET /articles/5/photos/4/comments/1 HTTP/1.1
We want the first comment of the fourth photo for the fifth article
GET /articles/5/photos/4/comments?page=1&limit=10
We want all comments of the fourth photo for the fifth article
Level 1 - Resources
15
GET, OPTIONS, HEAD
POST, PUT, PATCH, LINK, UNLINK
DELETE
Level 2 - HTTP verbs
16
Manipulation of Resources CRUD to HTTP
verb mapping
Create = POST
Retrieve = GET
Update = PUT (or PATCH)
Delete = DELETE
17
Overview of (some) HTTP methods
HTTP Method Safe Idempotent
GET yes yes
HEAD yes yes
PUT no yes
POST no no
DELETE no yes
PATCH no no
18
HTTP Status Codes. Part I
HTTP Code Message Description
200 OK The request was processed and returned successfully. Nothing was
changed.
201 Created The new resource was created successfully
400 Bad Request Problem with the request, such as a missing, invalid or type mismatched
parameter
401 Unauthorized The request did not have valid authorization credentials
403 Forbidden Private data you are not allowed to access, or you've hit a rate limit.
404 Not Found Your URL is wrong, or the requested resource doesn't exist
500 Server Error If this persists please contact support. We log and review all errors but your
help often helps us fix it quicker.
19
HTTP Status Codes. Part II
Code range Message Description
1xx Information 100 - Continue
2xx Successful 201 - Created
3xx Redirection 301 - Moved Permanently
4xx Client Error 404 - Not Found
5xx Server Error 501 - Not Implemented
20
POST /articles HTTP/1.1
{ “title”: “Title” }
GET /articles/1 HTTP/1.1
{ “id”: 1, “title”: “Title” }
PATCH /articles/1 HTTP/1.1
{ “title”: “Title - 1” }
DELETE /articles/1 HTTP/1.1
{ “message”: “Article was deleted” }
Example
21
Server Response:
HTTP/1.1 201 Created
Response to a successful request
22
{
"id" : 12,
"subject" : "I have a question!",
"summary" : "Hi, ....",
"customer" : {
"name" : "Bob"
},
"assignedUser": {
"id" : 42,
"name" : "Jim",
// ...
Server Response:
HTTP/1.1 500 Server Error
Server: Apache
Content-Language: ru
Content-Type: application/json; charset=utf-8
Errors: Useful error message
23
{
"code" : 1234,
"message" : "Something bad happened :(",
"description" : "More details about the error here",
"documentation" : "http://somehost.api/errors/1234"
}
Server Response:
HTTP/1.1 400 Bad Request
Errors: Validation errors for PUT, PATCH and POST
24
{
"code" : 1024,
"message" : "Validation Failed",
"errors" : [
{
"code" : 5432,
"field" : "first_name",
"message" : "First name cannot have fancy characters"
},
{
"code" : 5622,
"field" : "password",
"message" : "Password cannot be blank"
}
//...
An important concept developing the REST API is the
Content Negotiation.
GET /api/v1/pages/10.html HTTP/1.1
GET /api/v1/pages/10.json HTTP/1.1
GET /api/v1/pages/10.xml HTTP/1.1
Content Negotiation
25
Content negotiation is a mechanism defined in the HTTP specification that
makes it possible to serve different versions of a document (or more generally, a
resource representation) at the same URI, so that user agents can specify which
version fit their capabilities the best.
Content Negotiation. Definition
GET /api/v1/pages/10 HTTP/1.1
Accept: application/json
Accept: application/xml
Accept: text/html
26
The user agent provides an Accept HTTP header that lists
acceptable media types and associated quality factors. The
server is then able to supply the version of the resource that
best fits the user agent's needs.
Content Negotiation. Quality factors
Accept: application/json; q=1.0, application/xml; q=0.8,
text/html; q=0.6, text/*; q=0.1
27
HATEOAS - Hypermedia As The Engine Of Application State
Level 3 - Hypermedia Controls
The point of hypermedia controls is that they tell us what we can do next, and
the URI of the resource we need to manipulate to do it.
● Use links to allow clients to discover locations and operations
● Link relations are used to express options
● Clients do not need to know URLs
● This controls the state
28
Level 3 - HATEOAS: Links and relations
<articles>
<article>
<id>1</id>
<title>Title - 1</title>
<link href="http://example.com/articles/1" rel="self" />
<link href="http://example.com/articles/1/catalogs"
rel="catalogs" />
</article>
<article>
<id>2</id>
<title>Title - 2</title>
<link href="http://example.com/articles/2" rel="self" />
<link href="http://example.com/articles/2/catalogs"
rel="catalogs" />
</article>
<link href="http://example.com/articles?page=1" rel="prev" />
<link href="http://example.com/articles?page=2" rel="self" />
<link href="http://example.com/articles?page=3" rel="next" />
29
Level 3 - HATEOAS: Media types
The second part is about adding media types to answer the
question: What?. What is this resource? What does it contain
or what do I need to create such a resource?
This part introduces your own content type:
Content-Type: application/vnd.yourname.something+xml
30
Level 3 - HATEOAS: Version
First, you can add the version number in your URIs, this is the
easy way:
/api/v1/users
You can use your new content type:
application/vnd.acme.pave-v1+xml
31
Development Rest API in Symfony2
32
To be continued...
References
https://ru.wikipedia.org/wiki/REST
Wiki
http://restcookbook.com
REST CookBook
http://restful-api-design.readthedocs.org/en/latest/
Thoughts on RESTful API Design
http://www.crummy.com/writing/speaking/2008-QCon/act3.html
Leonard Richardson The Maturity Heuristiс
http://martinfowler.com/articles/richardsonMaturityModel.html
Richardson Maturity Model
http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
Best Practices for Designing a Pragmatic RESTful API
34
Thank you
Questions ?
Aleksey Kryvtsov alkryvtsov@gmail.com
35

More Related Content

What's hot

Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkVance Lucas
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2RORLAB
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weiboshaokun
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgnitermirahman
 
AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkBackand Cohen
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Flask patterns
Flask patternsFlask patterns
Flask patternsit-people
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Antonio Peric-Mazar
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2RORLAB
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編Masakuni Kato
 

What's hot (20)

Zend framework
Zend frameworkZend framework
Zend framework
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro Framework
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
 

Viewers also liked

Take a Groovy REST
Take a Groovy RESTTake a Groovy REST
Take a Groovy RESTRestlet
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Autenticazione delle api con jwt e symfony (Italian)
Autenticazione delle api con jwt e symfony (Italian)Autenticazione delle api con jwt e symfony (Italian)
Autenticazione delle api con jwt e symfony (Italian)Marco Albarelli
 
Building a documented RESTful API in just a few hours with Symfony
Building a documented RESTful API in just a few hours with SymfonyBuilding a documented RESTful API in just a few hours with Symfony
Building a documented RESTful API in just a few hours with Symfonyolrandir
 
PHP, non lo stesso vecchio linguaggio
PHP, non lo stesso vecchio linguaggioPHP, non lo stesso vecchio linguaggio
PHP, non lo stesso vecchio linguaggioMassimiliano Arione
 
Gestione delle dipendenze con Composer
Gestione delle dipendenze con ComposerGestione delle dipendenze con Composer
Gestione delle dipendenze con ComposerMassimiliano Arione
 
A Practical Introduction to Symfony2
A Practical Introduction to Symfony2A Practical Introduction to Symfony2
A Practical Introduction to Symfony2Kris Wallsmith
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSSmile I.T is open
 
Introduzione pratica a Symfony
Introduzione pratica a SymfonyIntroduzione pratica a Symfony
Introduzione pratica a SymfonyEugenio Minardi
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Présentation sur l'accessibilité numérique / Evènement université de Lille 3
Présentation sur l'accessibilité numérique / Evènement université de Lille 3 Présentation sur l'accessibilité numérique / Evènement université de Lille 3
Présentation sur l'accessibilité numérique / Evènement université de Lille 3 Smile I.T is open
 
20120525 졸업작품 발표
20120525 졸업작품 발표20120525 졸업작품 발표
20120525 졸업작품 발표SeonMan Kim
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architectureDaniele D'Angeli
 

Viewers also liked (20)

FHIR & Ice
FHIR & IceFHIR & Ice
FHIR & Ice
 
Take a Groovy REST
Take a Groovy RESTTake a Groovy REST
Take a Groovy REST
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Autenticazione delle api con jwt e symfony (Italian)
Autenticazione delle api con jwt e symfony (Italian)Autenticazione delle api con jwt e symfony (Italian)
Autenticazione delle api con jwt e symfony (Italian)
 
Building a documented RESTful API in just a few hours with Symfony
Building a documented RESTful API in just a few hours with SymfonyBuilding a documented RESTful API in just a few hours with Symfony
Building a documented RESTful API in just a few hours with Symfony
 
Http and REST APIs.
Http and REST APIs.Http and REST APIs.
Http and REST APIs.
 
PHP, non lo stesso vecchio linguaggio
PHP, non lo stesso vecchio linguaggioPHP, non lo stesso vecchio linguaggio
PHP, non lo stesso vecchio linguaggio
 
Gestione delle dipendenze con Composer
Gestione delle dipendenze con ComposerGestione delle dipendenze con Composer
Gestione delle dipendenze con Composer
 
The road to php7
The road to php7The road to php7
The road to php7
 
A Practical Introduction to Symfony2
A Practical Introduction to Symfony2A Practical Introduction to Symfony2
A Practical Introduction to Symfony2
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
 
Introduzione pratica a Symfony
Introduzione pratica a SymfonyIntroduzione pratica a Symfony
Introduzione pratica a Symfony
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
PHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuroPHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuro
 
Présentation sur l'accessibilité numérique / Evènement université de Lille 3
Présentation sur l'accessibilité numérique / Evènement université de Lille 3 Présentation sur l'accessibilité numérique / Evènement université de Lille 3
Présentation sur l'accessibilité numérique / Evènement université de Lille 3
 
From * to Symfony2
From * to Symfony2From * to Symfony2
From * to Symfony2
 
20120525 졸업작품 발표
20120525 졸업작품 발표20120525 졸업작품 발표
20120525 졸업작품 발표
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
30 Symfony Best Practices
30 Symfony Best Practices30 Symfony Best Practices
30 Symfony Best Practices
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architecture
 

Similar to Service approach for development Rest API in Symfony2

Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developersPatrick Savalle
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
Indic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhIndic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhAnirudh Bhatnagar
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlXebia IT Architects
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Gaurav Bhardwaj
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIsTom Johnson
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 

Similar to Service approach for development Rest API in Symfony2 (20)

Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Indic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhIndic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudh
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
11 asp.net web api
11 asp.net web api11 asp.net web api
11 asp.net web api
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST url
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIs
 
L18 REST API Design
L18 REST API DesignL18 REST API Design
L18 REST API Design
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 

More from Sumy PHP User Grpoup

Using Elastic Search Outside Full-Text Search
Using Elastic Search Outside Full-Text SearchUsing Elastic Search Outside Full-Text Search
Using Elastic Search Outside Full-Text SearchSumy PHP User Grpoup
 
Путешествия во времени
Путешествия во времениПутешествия во времени
Путешествия во времениSumy PHP User Grpoup
 
High Availability в жизни обычного разработчика
High Availability в жизни обычного разработчикаHigh Availability в жизни обычного разработчика
High Availability в жизни обычного разработчикаSumy PHP User Grpoup
 

More from Sumy PHP User Grpoup (6)

Web and IoT
Web and IoTWeb and IoT
Web and IoT
 
Using Elastic Search Outside Full-Text Search
Using Elastic Search Outside Full-Text SearchUsing Elastic Search Outside Full-Text Search
Using Elastic Search Outside Full-Text Search
 
Путешествия во времени
Путешествия во времениПутешествия во времени
Путешествия во времени
 
High Availability в жизни обычного разработчика
High Availability в жизни обычного разработчикаHigh Availability в жизни обычного разработчика
High Availability в жизни обычного разработчика
 
Php micro frameworks
Php micro frameworksPhp micro frameworks
Php micro frameworks
 
Oro open source solutions
Oro open source solutionsOro open source solutions
Oro open source solutions
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Service approach for development Rest API in Symfony2

  • 1. Service approach for development Rest API in Symfony2 Aleksey Kryvtsov @ Web-developer at CPCS alkryvtsov@gmail.com
  • 3. HISTORY REST was defined by Roy Thomas Fielding in 2000 In his dissertation "Architectural Styles and the Design of Network - based Software Architectures" 3
  • 4. ● Client - server ● Stateless ● Cacheable ● Layered system ● Uniform interface: ○ Identification of resources ○ Manipulation of resources through these representations ○ Self-descriptive messages ○ Hypermedia as the engine of application state (HATEOAS) ARCHITECTURAL CONSTRAINTS 4
  • 5. CLIENT - SERVER | STATELESS 5
  • 6. CACHEABLE Unsafe methods Safe methods GET /articles/1234 HTTP/1.1 - example of safe method PUT /articles/1234 HTTP/1.1 - example of unsafe method 6
  • 7. CACHING PROCESS GET /articles/1234 HTTP/1.1 - The resource is not cached yet - Send request to the API - Store response in cache and return GET /articles/1234 HTTP/1.1 - The resource is cached - Return response from cache PUT /articles/1234 HTTP/1.1 - Unsafe method, send to API PURGE /articles/1234 HTTP/1.1 - API sends PURGE method to the cache - The resources is removed from the cache GET /articles/1234 HTTP/1.1 - The resource is not cached yet - Send request to the API - Store response in cache and return 7
  • 9. Identification of resources GET /article/1234 HTTP/1.1 9
  • 10. Manipulation of resources through these representations {"Title": "Your title", "Text": "Your text"} {"id": 1, "Title": "Your title", "Text": "Your text"} JSON POST /articles HTTP/1.1 10
  • 11. 11 Self-descriptive messages Request: GET /articles/1234 HTTP/1.1 Host: test.host.com User-Agent: Mozilla/5.0 Accept: application/json Connection: close (empty line) 11 Server Response: HTTP/1.1 200 OK Date: Wed, 16 Mar 2016 11:20:59 GMT Server: Apache Content-Language: ru Content-Type: application/json; charset=utf-8 Content-Length: 1234 Connection: close (empty line) (json representation)
  • 12. BENEFITS ● Reliability ● Performance ● Scalability ● Simplicity ● Portability ● Modifiability ● Visibility 12
  • 13. REST design maturity levels (Richardson Maturity Model) 13
  • 15. GET /articles HTTP/1.1 We want all articles GET /articles/5/photos/4/comments/1 HTTP/1.1 We want the first comment of the fourth photo for the fifth article GET /articles/5/photos/4/comments?page=1&limit=10 We want all comments of the fourth photo for the fifth article Level 1 - Resources 15
  • 16. GET, OPTIONS, HEAD POST, PUT, PATCH, LINK, UNLINK DELETE Level 2 - HTTP verbs 16
  • 17. Manipulation of Resources CRUD to HTTP verb mapping Create = POST Retrieve = GET Update = PUT (or PATCH) Delete = DELETE 17
  • 18. Overview of (some) HTTP methods HTTP Method Safe Idempotent GET yes yes HEAD yes yes PUT no yes POST no no DELETE no yes PATCH no no 18
  • 19. HTTP Status Codes. Part I HTTP Code Message Description 200 OK The request was processed and returned successfully. Nothing was changed. 201 Created The new resource was created successfully 400 Bad Request Problem with the request, such as a missing, invalid or type mismatched parameter 401 Unauthorized The request did not have valid authorization credentials 403 Forbidden Private data you are not allowed to access, or you've hit a rate limit. 404 Not Found Your URL is wrong, or the requested resource doesn't exist 500 Server Error If this persists please contact support. We log and review all errors but your help often helps us fix it quicker. 19
  • 20. HTTP Status Codes. Part II Code range Message Description 1xx Information 100 - Continue 2xx Successful 201 - Created 3xx Redirection 301 - Moved Permanently 4xx Client Error 404 - Not Found 5xx Server Error 501 - Not Implemented 20
  • 21. POST /articles HTTP/1.1 { “title”: “Title” } GET /articles/1 HTTP/1.1 { “id”: 1, “title”: “Title” } PATCH /articles/1 HTTP/1.1 { “title”: “Title - 1” } DELETE /articles/1 HTTP/1.1 { “message”: “Article was deleted” } Example 21
  • 22. Server Response: HTTP/1.1 201 Created Response to a successful request 22 { "id" : 12, "subject" : "I have a question!", "summary" : "Hi, ....", "customer" : { "name" : "Bob" }, "assignedUser": { "id" : 42, "name" : "Jim", // ...
  • 23. Server Response: HTTP/1.1 500 Server Error Server: Apache Content-Language: ru Content-Type: application/json; charset=utf-8 Errors: Useful error message 23 { "code" : 1234, "message" : "Something bad happened :(", "description" : "More details about the error here", "documentation" : "http://somehost.api/errors/1234" }
  • 24. Server Response: HTTP/1.1 400 Bad Request Errors: Validation errors for PUT, PATCH and POST 24 { "code" : 1024, "message" : "Validation Failed", "errors" : [ { "code" : 5432, "field" : "first_name", "message" : "First name cannot have fancy characters" }, { "code" : 5622, "field" : "password", "message" : "Password cannot be blank" } //...
  • 25. An important concept developing the REST API is the Content Negotiation. GET /api/v1/pages/10.html HTTP/1.1 GET /api/v1/pages/10.json HTTP/1.1 GET /api/v1/pages/10.xml HTTP/1.1 Content Negotiation 25
  • 26. Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource representation) at the same URI, so that user agents can specify which version fit their capabilities the best. Content Negotiation. Definition GET /api/v1/pages/10 HTTP/1.1 Accept: application/json Accept: application/xml Accept: text/html 26
  • 27. The user agent provides an Accept HTTP header that lists acceptable media types and associated quality factors. The server is then able to supply the version of the resource that best fits the user agent's needs. Content Negotiation. Quality factors Accept: application/json; q=1.0, application/xml; q=0.8, text/html; q=0.6, text/*; q=0.1 27
  • 28. HATEOAS - Hypermedia As The Engine Of Application State Level 3 - Hypermedia Controls The point of hypermedia controls is that they tell us what we can do next, and the URI of the resource we need to manipulate to do it. ● Use links to allow clients to discover locations and operations ● Link relations are used to express options ● Clients do not need to know URLs ● This controls the state 28
  • 29. Level 3 - HATEOAS: Links and relations <articles> <article> <id>1</id> <title>Title - 1</title> <link href="http://example.com/articles/1" rel="self" /> <link href="http://example.com/articles/1/catalogs" rel="catalogs" /> </article> <article> <id>2</id> <title>Title - 2</title> <link href="http://example.com/articles/2" rel="self" /> <link href="http://example.com/articles/2/catalogs" rel="catalogs" /> </article> <link href="http://example.com/articles?page=1" rel="prev" /> <link href="http://example.com/articles?page=2" rel="self" /> <link href="http://example.com/articles?page=3" rel="next" /> 29
  • 30. Level 3 - HATEOAS: Media types The second part is about adding media types to answer the question: What?. What is this resource? What does it contain or what do I need to create such a resource? This part introduces your own content type: Content-Type: application/vnd.yourname.something+xml 30
  • 31. Level 3 - HATEOAS: Version First, you can add the version number in your URIs, this is the easy way: /api/v1/users You can use your new content type: application/vnd.acme.pave-v1+xml 31
  • 32. Development Rest API in Symfony2 32
  • 34. References https://ru.wikipedia.org/wiki/REST Wiki http://restcookbook.com REST CookBook http://restful-api-design.readthedocs.org/en/latest/ Thoughts on RESTful API Design http://www.crummy.com/writing/speaking/2008-QCon/act3.html Leonard Richardson The Maturity Heuristiс http://martinfowler.com/articles/richardsonMaturityModel.html Richardson Maturity Model http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api Best Practices for Designing a Pragmatic RESTful API 34
  • 35. Thank you Questions ? Aleksey Kryvtsov alkryvtsov@gmail.com 35