I'm trying to create a website that also have rest api
I use mvc structure for this website.
So what is the better way to create such website? I see 2 option and for each one I have question that can't figure out which one is better ( I use login action for example in both option )
Option 1: Create a controller for login and also create a endpoint for api, and write all login in two file. This option is really code for example I can add extra condition for login via api. But the problem is If I want to add a new logic for login, I must add it in two file.
Option 2: create a file ( I'm not sure what should call it, service ? ) and In both file call login method from that file.
And here is my questions:
1-Which way is better? ( Also maybe I can use another option ? )
2-In MVC is there a pattern for option 2? what it's name?
3-I always use option 1, and also see a lot of example doing that way, Is this correct to repeat code?
Aucun commentaire:
Enregistrer un commentaire