Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it wise to build an MVC app around a RESTful API using nothing but HttpClient?

My boss wants a full REST API for our new project. But, he also wants a UI for it and our deadline is not very generous. Learning a decent front-end framework (Angular, React, Vue) might prove to take a little too long.

He is asking if we could talk to the REST API using MVC entirely. I explained to him that MVC means the view is tightly coupled to the controller.

He asked why we cannot just build out the REST API fully, and then make an MVC app that uses HttpClient in the controller (or a service class) to hit the API.Is that a bad idea? I told him it seemed like another big layer to maintain and that most people are probably using a nice front-end framework to talk to their back-end.

I also felt like I did not know enough about how other people handle this situation. So those of you that MUST have a REST API for all new apps. How do you build your UI for it? We are using Swagger, so generating TypeScript or C# clients is possible if that helps.

like image 249
Victorio Berra Avatar asked Mar 26 '18 16:03

Victorio Berra


People also ask

Can we use REST API in MVC?

First, create an ASP.NET Web application project in Visual Studio and call it RestAPI. You can do this by selecting File->New->Project->ASP.NET Web Application and clicking OK. After clicking the OK button, the following window would get displayed from where you need to select the Web API and click the OK button.

Can we create Web API without MVC?

An API is supposed to provide services without being coupled with its consumer application. There is a common misconception that for developing Web APIs, we have to go by ASP.NET MVC application. In this article, we will develop an independent API which is not coupled with a ASP.NET MVC application type.

Do REST APIs always use HTTP?

REST is not necessarily tied to HTTP. RESTful web services are just web services that follow a RESTful architecture.


1 Answers

Learning a decent front-end framework (Angular, React, Vue) might prove to take a little too long.

MVC is a decent front-end framework. Do you disagree?

He is asking if we could talk to the REST API using MVC entirely. I explained to him that MVC means the view is tightly coupled to the controller.

He's right and MVC doesn't tightly-couple you to anything. Bad programming tightly-couples.

He asked why we cannot just build out the REST API fully, and then make an MVC app that uses HttpClient in the controller (or a service class) to hit the API.Is that a bad idea?

MVC to API is very common. Like your boss said, you have your MVC (UI Layer) controller connect to your API using an HttpClient instance. He's got it nailed here.

What your boss is describing is a very common thing in the Microsoft stack.

like image 111
Big Daddy Avatar answered Nov 14 '22 15:11

Big Daddy