0

I'm going to create an api with api-platform and I want to separate my business logic from framework.

For example I want to allow users to register new accounts and POST: /user is good for that. Api-platform is doing all the magic (handler request, validate data, save new user (doctrine), return response). But my business logic wants to send invitation email and make other things during creating new user. How should I do that to be fine with api-platform?

Should I create custom operation POST: /register, inside call my use-case register($user)? Should I create custom repository interface and inside save(User) implementation call POST: /user?

Or should I use event system and split my "big" use-case (register) to small ones depends on what my business logic need to do (validate data, send invitation email, etc.)? And if I want to register new user from CLI my command has to use all of this small use-cases?

Or should I completely forget about all api-platform magic and if my business logic is more then CRUD I have to care of everything by my self (validate data, save to DB, send email, etc.)?

d0niek
  • 173
  • 11

1 Answers1

0

There are a places for custom business logic https://api-platform.com/docs/core/extending/.

Good point to add business logic are Data Persisters. I can use there my own Repository to save user, send email, etc.

d0niek
  • 173
  • 11