0

I have an MVC application that uses MVC Controllers to return views. Now I want to expose an API to other applications to consume, as well as returning JSON data types for some SPA features in the same MVC. What are the differences between adding Web API Controllers to my MVC Project vs adding a whole new Web API Project?

2
  • This question is too vague because the topic is big. Are there specific differences (or areas) you are concerned about? If not, I'd just add them to your current project because you can always migrate them to a separate project later. Commented May 3, 2016 at 16:34
  • I understand. As far as I know, I just need to add Web Api Controllers to my current project, but I wanted to know what would be the benefits of adding a separate Web Api Project and create them there. Commented May 3, 2016 at 16:37

2 Answers 2

1

returning JSON data types for some SPA features in the same MVC

For that case, I'll place Web API inside existing MVC. By doing so, you can share business logic, services and even models.

In my case, I have SPA silos using AngularJS, and both MVC and Web API live happily in the same web application, and share business logic and data access layers.

It is worth noting that you can share Authentication cookie if you keep MVC and Web API together. Otherwise, it is pain in the neck to authenticate in both places at the same time, because Web API is token based and MVC is cookie based by default.

FYI: In new ASP.Net MVC 5, there won't be separate MVC and Web API anymore.

Sign up to request clarification or add additional context in comments.

1 Comment

I see. I was 80% sure about using that approach for my SPA concern. But, what about third party access to the API? Does it have any security implication having both API and MVC in the same application?
0

The only difference between the two is reusability and good design practice. I highly recommend to use it in a separate project. Then, later on, you will be able to reuse it without much or any effort.

Another advantage to segregate is the impact on testing required for any changes made. If you keep the projects different then if later on you change anything, the domain for the re-testing efforts would also be just the second project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.