Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Two APIs inside single app #2275

Closed
er1z opened this issue Oct 24, 2018 · 17 comments
Closed

[question] Two APIs inside single app #2275

er1z opened this issue Oct 24, 2018 · 17 comments

Comments

@er1z
Copy link
Contributor

er1z commented Oct 24, 2018

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.

@er1z
Copy link
Contributor Author

er1z commented Dec 10, 2018

Bump.

@soyuka
Copy link
Member

soyuka commented Dec 10, 2018

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 #2235 for more informations!

@er1z
Copy link
Contributor Author

er1z commented Dec 10, 2018

You didn't understand: I want to have separated APIs — one public, one internal. How do you recommend to achieve this?

@dunglas
Copy link
Member

dunglas commented Dec 10, 2018

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.

@er1z
Copy link
Contributor Author

er1z commented Dec 10, 2018

But how about swagger docs? And is this possible to have some common logic if two kernels are being used?

@teohhanhui
Copy link
Contributor

teohhanhui commented Dec 10, 2018

Just have 2 separate apps, but you can structure your code for reuse between the 2 apps.

@er1z
Copy link
Contributor Author

er1z commented Dec 10, 2018

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?

@teohhanhui
Copy link
Contributor

What about keeping them as a single API then? But using different prefixes as @dunglas has suggested.

@er1z
Copy link
Contributor Author

er1z commented Dec 10, 2018

But they will share Swagger docs what is the thing I don't want to.

@dunglas
Copy link
Member

dunglas commented Dec 10, 2018

You could decorate the Docker normalizer to filter the docs by prefix.

@er1z
Copy link
Contributor Author

er1z commented Dec 11, 2018

And then, how to access two swagger-based functionality — eg. API website and generate separated swagger.json|yml?

@soyuka
Copy link
Member

soyuka commented Dec 11, 2018

Same, decorate the documentation normalizer accordingly and allow only the prefixed data.

@er1z
Copy link
Contributor Author

er1z commented Dec 11, 2018

I know but how to access first and second one (mean how to distinguish which one I want to get/open at time)?

@er1z
Copy link
Contributor Author

er1z commented Dec 21, 2018

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:ex
  • bin/console api:swag:ex

API Docs:

  • header x-internal exists / query string with key is_internal any content <-> internal API
  • otherwise: external API

Based on decoration of provided services and conditional routes.

Please review and point how to do it better and what are pitfalls?

@er1z
Copy link
Contributor Author

er1z commented Jan 10, 2019

Bundled: https://github.com/er1z/multi-api-platform-bundle

My question, how to create unit-tests against such a decoration?

@stale
Copy link

stale bot commented Nov 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 5, 2022
@soyuka soyuka removed the question label Nov 6, 2022
@stale stale bot removed the wontfix label Nov 6, 2022
@api-platform api-platform locked and limited conversation to collaborators Nov 6, 2022
@soyuka soyuka converted this issue into discussion #5138 Nov 6, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants