lionframe - rapid restful api development
TRANSCRIPT
wykorzystanie API
• Współdzielenie treści i danych pomiędzy aplikacjami/systemami
• Budowanie aplikacji korzystających z serwisu
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
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
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)
Backend system
Mobile application
appointmentService
POST <openSlotRequest
POST <appointmentRequest
Level 0 THE SWAMP OF POX
Backend system
Mobile application
doctors/jdoe
POST <openSlotRequest
POST <appointmentRequest
slots/1234
Level 1 RESOURCES
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
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
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())
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)
FOS REST BUNDLE
• Wykrywa format po nagłówach HTTP
• Wybiera i zwraca response w porządanym formacie
• Integruje kontroler z serializerem
@micmarcinkowski @Lakion
lakion.com/lionframe
„Time is money” Benjamin Franklin
Image Credits
http://martinfowler.com/articles/richardsonMaturityModel.html
https://www.flickr.com/photos/kwl/4247555680