What do you recommend in order to create API within two contexts using API Platform: first — publicly available one and second: used by microservices within application cluster? To simplify — I rely on DTOs and do not expose any entities directly.
Bump.
Using DTO looks good. You can also leverage the new Input/Output feature if you want to have a resource class but different input/output classes. see https://github.com/api-platform/core/pull/2235 for more informations!
You didn't understand: I want to have separated APIs — one public, one internal. How do you recommend to achieve this?
I don't think that it's possible yet without having two kernels. Anyway, you can have a single API, but using different paths per resources (some in /internal, and some in /publish for instance) using the path and the prefix options.
But how about swagger docs? And is this possible to have some common logic if two kernels are being used?
Just have 2 separate apps, but you can structure your code for reuse between the 2 apps.
Yes, but's it's too early for this pre-mature optimization and I'm looking for a solution how to keep these within one app (both APIs share Entities, DTOs). Maintaining two apps is more absorbing than single one (at least at this product stadium). Isn't this possible?
What about keeping them as a single API then? But using different prefixes as @dunglas has suggested.
But they will share Swagger docs what is the thing I don't want to.
You could decorate the Docker normalizer to filter the docs by prefix.
And then, how to access two swagger-based functionality — eg. API website and generate separated swagger.json|yml?
Same, decorate the documentation normalizer accordingly and allow only the prefixed data.
I know but how to access first and second one (mean how to distinguish which one I want to get/open at time)?
Made something like this: https://github.com/er1z/api-platform-two-apis
PoC that separates DTOs: internal and external.
CLI:
IS_INTERNAL=true bin/console api:swag:exbin/console api:swag:exAPI Docs:
x-internal exists / query string with key is_internal any content <-> internal APIBased on decoration of provided services and conditional routes.
Please review and point how to do it better and what are pitfalls?
Bundled: https://github.com/er1z/multi-api-platform-bundle
My question, how to create unit-tests against such a decoration?
Most helpful comment
You could decorate the Docker normalizer to filter the docs by prefix.