The document discusses handling complex POST and PATCH requests in RESTful APIs. It describes a RESTful API called ProFIT that was created for a product fulfillment and information tracking system. The API has around 60 entities and 100 endpoints and supports GET, POST, PUT, PATCH requests. Examples are provided for GET requests to retrieve orders and their items, as well as POST and PATCH requests. The benefits of using data transfer objects and serialization libraries like JMSSerializerBundle and SimpleThingsFormSerializerBundle are covered. The presentation also discusses validation, authentication, testing, and best practices for building RESTful APIs with Symfony.
6. RESTful API, examples GET
GET /api/machines/KARAT+1/hot-folders GET /api/product-box-types/12-type/associations
The server response: The server response:
[ [
{ {
"path":"/home/somepath/", "id": 1,
"types": [ "product": "business_cards",
"34-f-Type", "quantity": 1000
"33-S-Type", },
...... ......
] ]
},
......
]
GET /api/press-sheets/134/label
The server response:
{
"label": "epl string"
}
Dmitry Petrov
7. RESTful API, examples POST / PUT
POST http://localhost/api/orders, POST http://localhost/api/press-sheets/12/transition
PUT http://localhost/api/orders/12 Body of the request:
Body of the request: {
{ "transition": "start:printing:front",
"id": 12, "note": null
"client": { }
"firstname": "Dmitry",
"lastname": "Petrov",
"email": "",
"phone": null,
"address": {
"country": "Russia",
"city": "Saratov",
"zip": 123456,
"street": "Vavilova",
"residentional": false
}
}
}
Dmitry Petrov
22. RESTful API, JMSSerializerBundle
Problems / Disadvantages
GET - serialization of null values
PATCH - deserialized into an object
PATCH - merge null values
MERGE - a lot of useless code
Dmitry Petrov
26. SimpleThingsFormSerializerBundle
Problems / Disadvantages
Converting data into string
Lack of support PATCH method (v. 2.0)
The ideological aversion
The dirty mix *Type and *DTO
Dmitry Petrov
30. Reinvent the wheel
Requirements
(Un)Serialization of objects
Preservation of the type in data
Metadata cache
Dmitry Petrov
31. Reinvent the wheel
Assumptions
The output format is json
Metadata is stored in yml
There are get/set methods
Dmitry Petrov
32. Reinvent the wheel
After 36 hours... train Saratov - Kiev is comming 30 hours
SimpleSerializer
SimpleSerializerBundle
Details can be found on the habr
Dmitry Petrov
33. SimpleSerializer
Benefits
This is library
Separation of serialization rules and format
Absence voiced disadvantages
"Inteligent" deserialization
Dmitry Petrov