Top Banner
Lionframe Rapid RESTful API development powered by
34
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lionframe - Rapid RESTful API development

LionframeRapid RESTful API development

powered by

Page 2: Lionframe - Rapid RESTful API development

Michał Marcinkowski

Współzałożyciel LAKION

Miłośnik Symfony2 i Open Source

Page 3: Lionframe - Rapid RESTful API development

?Co to jest API

Page 4: Lionframe - Rapid RESTful API development

Application Programming

Interface

Page 5: Lionframe - Rapid RESTful API development

User Interface

Page 6: Lionframe - Rapid RESTful API development

User Interface

Page 7: Lionframe - Rapid RESTful API development

Software-to-software Interface

Page 8: Lionframe - Rapid RESTful API development

Amazon Client

My website Client

API

UI

UI

Page 9: Lionframe - Rapid RESTful API development

wykorzystanie API

• Współdzielenie treści i danych pomiędzy aplikacjami/systemami

• Budowanie aplikacji korzystających z serwisu

Page 10: Lionframe - Rapid RESTful API development

?Czy każda aplikacja zależy od jakiegoś API

Page 11: Lionframe - Rapid RESTful API development

?Czy każda aplikacja zależy od jakiegoś APITAK!

Page 12: Lionframe - Rapid RESTful API development

REST

Page 13: Lionframe - Rapid RESTful API development

CECHY REST• Bezstanowość

• Cache

• Jednolitość interfejsów

• Oparte na standardach (HTTP, URL, XML, JSON)

• Niezależność od platformy i języka

• Może być stosowane w obecności firewalli

• Prostota

Page 14: Lionframe - Rapid RESTful API development

Prostota RESTPOST / HTTP/1.1

Host: www.example.org Content-Type: application/soap+xml; charset=utf-8

Content-Length: 300

<?xml version="1.0"?> <soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/"> <m:GetUserDetails>

<m:UserID>12345</UserID> </m:GetUserDetails>

</soap:Body> </soap:Envelope>

GET /users/12345 HTTP/1.1 Host: www.example.org Accept: application/json

Page 15: Lionframe - Rapid RESTful API development

Dojrzałość REST

Richardson Maturity Model

Page 16: Lionframe - Rapid RESTful API development

Level 0 THE SWAMP OF POX

• Protokół jako tunel dla request-response (zazwyczaj HTTP)

• Jeden entry point URI

• Jeden rodzaj metody (w HTTP, zazwyczaj metoda POST)

Page 17: Lionframe - Rapid RESTful API development

Backend system

Mobile application

appointmentService

POST <openSlotRequest

POST <appointmentRequest

Level 0 THE SWAMP OF POX

Page 18: Lionframe - Rapid RESTful API development

Level 1 RESOURCES

• Wiele URIs • Każdy URI inny resource • Jeden rodzaj metody (POST)

Page 19: Lionframe - Rapid RESTful API development

Backend system

Mobile application

doctors/jdoe

POST <openSlotRequest

POST <appointmentRequest

slots/1234

Level 1 RESOURCES

Page 20: Lionframe - Rapid RESTful API development

Level 2 HTTP VERBS

• Używanie poprawnych metod

• Używanie poprawnych kodów odpowiedzi

Page 21: Lionframe - Rapid RESTful API development

Level 2 HTTP VERBS

• GET

• POST

• PUT

• PATCH

• DELETE

Page 22: Lionframe - Rapid RESTful API development

HTTP CODES• 2xx Success

• 200 OK

• 201 Created

• 204 No Content

• 3xx Redirection

• 301 Moved Permanently

• 5xx Server Error

• 500 Internal Server Error

• 503 Service Unavailable

• 4xx Client Error

• 400 Bad Request

• 401 Unauthorized

• 403 Forbidden

• 404 Not Found

• 405 Method Not Allowed

• 409 Conflict

Page 23: Lionframe - Rapid RESTful API development

Level 3 Hypermedia controls

• Używanie HATEOAS do odkrywania możliwości API

Page 24: Lionframe - Rapid RESTful API development

DEMO Time

Page 25: Lionframe - Rapid RESTful API development

/** * @Assert\NotBlank() */ private $firstName;

VALIDATIOn

Page 26: Lionframe - Rapid RESTful API development

SERIALIZACJA#src/Acme/DemoBundle/Resources/config/serializer/Entity.Player.yml Acme\DemoBundle\Entity\Player: exclusion_policy: ALL xml_root_name: player properties: id: expose: true type: integer xml_attribute: true firstName: expose: true type: string lastName: expose: true type: string

Page 27: Lionframe - Rapid RESTful API development

HATEOAS#src/Acme/DemoBundle/Resources/config/serializer/Entity.Player.yml Acme\DemoBundle\Entity\Player: exclusion_policy: ALL xml_root_name: player properties: id: expose: true type: integer xml_attribute: true firstName: …. relations: - rel: self href: route: acme_api_player_show parameters: id: expr(object.getId())

Page 28: Lionframe - Rapid RESTful API development

Z czego składa się LIONframe

Page 29: Lionframe - Rapid RESTful API development

Sylius Resource Bundle

• Domyślny kontroler

• Domyślny routing

• Domyślne repository z paginacją

• Aliasy do serwisów dla managerów, repository, kontrolerów

• Podstawowe filtrowanie i sortowanie

• Wywołuje zdarzenia (events)

Page 30: Lionframe - Rapid RESTful API development

FOS REST BUNDLE

• Wykrywa format po nagłówach HTTP

• Wybiera i zwraca response w porządanym formacie

• Integruje kontroler z serializerem

Page 31: Lionframe - Rapid RESTful API development

JMS Serializer BUNDLE

• Serializuje dane do opowiedniego formatu

• Łatwo konfigurowalny serializer

Page 32: Lionframe - Rapid RESTful API development

BaZinga hateoas Bundle

• Dodaje linki relacji

• Obsługuje XML i JSON

• Łatwo konfigurowalne relacje

Page 33: Lionframe - Rapid RESTful API development

@micmarcinkowski @Lakion

lakion.com/lionframe

„Time is money” Benjamin Franklin

Page 34: Lionframe - Rapid RESTful API development

Image Credits

http://martinfowler.com/articles/richardsonMaturityModel.html

https://www.flickr.com/photos/kwl/4247555680