0

I am quite perplexed over the use of Web Api in a MVC application being developed at my company.I recently joined the project and wondering why they are using this.The application uses JQuery AJAX functionality to pull data for each Tab in a MultiTab Page without refreshing it.

The application here is neither providing data service nor consuming any Web API service.This can be easily achieved without using REST verbs.It is directly connecting to database like a typical web application.

I am holding back myself to raise this question with the team since I haven't used Web API much but has a conceptual idea.

Am I missing something here ?

raj'sCubicle
  • 350
  • 2
  • 13
  • This may be a question better suited for programmers.se than stackoverflow – jleach Apr 27 '16 at 02:45
  • Possible duplicate of [Difference between MVC 5 Project and Web Api Project](http://stackoverflow.com/questions/22589245/difference-between-mvc-5-project-and-web-api-project) – Ian Mercer Apr 27 '16 at 02:57
  • 1
    @jdl134679 when referring other sites, it is often helpful to point that [cross-posting is frowned upon](http://meta.stackexchange.com/tags/cross-posting/info) – gnat Apr 27 '16 at 05:15

2 Answers2

0

Microsoft's Web API MVC technology is typically used for external components to interact with the system - not generally a requirement for a standard MVC Web Application.

With that said, I'm not perfectly clear on the architecture. A few points of note:

  • jQuery AJAX is a perfectly valid (and usually preferred) method to retrieve information for tab pages - it provides a SPA (Single Page Application) "feel" to the site and generally improves performance all around. This does not mean that they're using a Web API
  • MVC is a framework used for many web applications, including Microsoft's Web API projects as well as ASP.NET MVC Web projects. The use of MVC doesn't mean that they're using a Web API.
  • A RESTful approach isn't just for Web APIs. Indeed, many find it a cleaner approach when using regular MVC Web Applications, as it tends to be more semantic to what actions are actually being performed (GET to get a view, POST to post data, DELETE, etc.) There's no real reason not to use REST verbs (which are actually just HTTP verbs, but called "REST" when we use them in a certain way). The use of HTTP verbs doesn't mean that we're using a Web API.

To conclude, The MVC Web API framework is it's own technology that's similar to MVC Web Applications, but more geared towards working with non-visual requests and responses, instead tailored to programmatic interfacing.

If this is indeed a Web API being used and not a case of MVC practices that you happen to be unfamiliar with, then yes, I think it's a good question to raise (at least from a technical standpoint - politically, maybe not, but we can't answer that for you).

A typical setup is to have multiple projects, one of which is a Web Application, which makes use of shared project(s) for domain/business classes and data persistence. Additionally, a Web API project is often used to provide access to the system for external components, but this is a separate "presentation layer" project from the aforementioned Web Application.

There may be cases where a Web API application is written as the core interface between the internal system and the rest of the outside world, where the MVC Web Application then interacts with the Web API, but this is a corner case that should only be done with specific reason, in my opinion (unless I misread, this seems to be the case you're stating?)

jleach
  • 7,410
  • 3
  • 33
  • 60
  • Thanks for an insightful response. We can adopt the restful approach in my current project even without using Web Api.At what cost a Restful Approach using WebApi can be made ?. – raj'sCubicle Apr 27 '16 at 12:35
0

Using both MVC and WebAPI together in a ASP.NET Web application is quite common. Whilst you can provide HTML through WebAPI and you can provide JSON through MVC it's much cleaner to use the best technology for each.

WebAPI in particular lets you define an API once and then generates JSON, XML, ... for you based on the request.

Ian Mercer
  • 38,490
  • 8
  • 97
  • 133
  • This application we are working on doesn't need to serve different types of formats(JSON,XML..).The UI is making calls to them as partial postbacks and is fine with just JSON.But we can achieve this even without using WEB Api.Aren't we overloading the application with Web Api ? – raj'sCubicle Apr 27 '16 at 12:28
  • No, you aren't overloading it, you are improving it. – Ian Mercer Apr 27 '16 at 13:59