Should I use my own web API

I am browsing a web API and I'm not sure how asp.net mvc and web api can or should work together.

I want to implement Backbone on the client side, but I'm not sure if I have to implement ApiController or a regular controller on the server side?

The way I do things (getting current user / account information) is that the base ApiController will have the same functions as the base controller, which will lead to duplication of functionality, but not sure if there will be other compromises.

Or will you create an ApiController for the public service you want to provide and stick with the controllers for the web application?

+1
source share
2 answers

If you are planning an API, use ApiController. If you use the web interface, use the classic controller. This is what both are made for.

+1
source

This is almost the situation I am in, except that I use Knockout.js and not Backbone. I have views for Create and Edit and in each view there is a very complex Knockout.js user interface that loads Ajaxing JSON back to the server.

In MVC3, I used many JsonResult methods inside the same controller that displayed the views. I experimented with RC MVC4 and wondered if I should follow the "ho" path of using the API controller for Ajax requests. I like strongly typed HTTP classes and the fact that JSON.NET is more integrated, but at this point I have to say that the end result of having a separate API controller for my internal use was simply not right. Like you, I found that I had a lot of duplication around security, and the separation of what was connected with the logic simply by the type of content made things more confusing rather than clean.

So at the moment (although I was already known), I plan to use standard MVC controllers for my current context, but I can take the opportunity to use the brilliant new web API if I ultimately expose the public API.

0
source

Source: https://habr.com/ru/post/920450/


All Articles