1.2 KiB
1.2 KiB
Custom API methods with DTO
This example demonstrates how you can use your custom serializer with custom DTOs to implement API methods.
How to run the project
- Open
app.php
and change credentials and the site to your data. - Run these commands:
composer install
php app.php
You will see something like this:
Created customer using custom methods. ID: 5633
This means that the project works as expected.
Navigation
app.php
- entrypoint, calls the custom method and outputs the response data.src/Component/Adapter/SymfonyToLiipAdapter.php
- adapter for usingsymfony/serializer
insideFormEncoder
component.src/Component/CustomApiMethod.php
-CustomApiMethod
that usesSerializerInterface
fromliip/serializer
andFormEncoder
. This component will handle marshaling.src/Dto
- data models used in the project.src/Factory/SerializerFactory.php
- buildssymfony/serializer
's serializer and wraps it into theSymfonyToLiipAdapter
.src/Factory/ClientFactory.php
- custom client factory that register the custom API method.