Is it possible to create an MVC application around a RESTful API using only HttpClient?

My boss wants a complete REST API for our new project. But he also wants to create a user interface for him, and our deadline is not very generous. Learning a decent interface structure (Angular, React, Vue) may be too long.

He asks if we can talk to the REST API using the entire MVC. I explained to him that MVC means that the view is closely related to the controller.

He asked why we cannot just completely create the REST API and then create an MVC application that uses the HttpClient in the controller (or service class) to get into the API. It is a bad idea? I told him that this looked like another big layer for support, and that most people probably use a nice front-end infrastructure to communicate with them retroactively.

It also seemed to me that I did not know enough about how other people deal with this situation. Therefore, those of you who MUST have a REST API for all new applications. How do you build your interface for this? We use Swagger, so generating TypeScript or C # clients is possible if this helps.

+5
source share
4 answers

Learning a decent interface structure (Angular, React, Vue) may take too long.

MVC is a decent interface infrastructure. Do you disagree?

He asks if we can talk to the REST API using the entire MVC. I explained to him that MVC means that the view is closely related to the controller.

He's right, and MVC is not tight, with nothing. Poor dense-steam programming.

He asked why we cannot just completely create a REST API, and then make an MVC application that uses the HttpClient in the controller (or service class) to get into the API. It is a bad idea?

MVC for the API is very common. Like your boss, you have an MVC controller (UI Layer) connected to your API using an HttpClient instance. Here he nailed it.

What your boss describes is very common on the Microsoft stack.

+3
source

He asks if we can talk to the REST API using fully MVC.

Yes, this is very common. The current version of MVC is , basically MVC / WebApi , wrapped in one Framework.

I explained to him that MVC means that the view is closely related to the controller.

No. The controller really has nothing to do with anything other than building a model and routing to view. Every project that I built from scratch, the view does not know about the controller, and most of the time it knows only about the model passed to it (in other cases there is not even a model). Someone might tightly associate a view with a controller, but I would not recommend this.

He asked why we canโ€™t completely create a REST API,

You can, it is very easy, I do it almost all the time.

create an MVC application that uses the HttpClient in the controller (or service class) to get into the API.

This is a bad idea if , it is the same project. There is no reason to add another network layer. It does not give any value.

I also felt that I did not know enough about how other people deal with this situation.

So this is really my personal opinion. I have been working with Asp.net-mvc since version 2.0 using jQuery. I switched to using MVC with KnockoutJS , which moved 95% of the data to API calls, and most of my views have no models. I worked on projects with Angular, but based on my very limited knowledge, it was much harder to pick up and it seemed to take a lot more to make something simple. I am currently working with Kendo (like Knockout MVVM), and it does the job. In all of these cases, using the front-panel Javascript Frameworks, most of my views are model-independent, relying solely on the API.

If I were to start a new project with a limited time, IMHO MVC / WebAPI + Knockout is ridiculously simple. Again, this is my opinion based on my preferences and experiences.

HOWEVER warning: rant

Why does he want him to be REST Api? Seriously, I really hate it when any type of manager tells me which tools I should use to build a solution. This is the new / old SOA (Service Oriented Architecture) of our time. Sometimes adding a requirement without any reason just adds more time / resources to get the solution out of the door.

For instance:

Manager: I need to deliver the pallet to the destination. Create a vehicle that can carry one pallet to its destination as efficiently as possible. Oh, and he needs 4 doors!

Me: Why do I need four doors? Because you like 4 doors? Because it's a new hobby?

+1
source

My boss wants a complete REST API for our new project. But he also wants to create a user interface for him, and our deadline is not very generous.

If you use HTML as your media type, you can use any web browser that you like to render.

In some formats, json hyperlinks can also be browsers; for example, HAL author Mike Kelly has a github project for browser .

0
source

If your backend is in a relational database, and indeed your deadline is tight, here is an alternative to manually coding endopoints APIs. Take a look at SlashDB, which wraps the database in an intuitive read and write API and provides a graphical interface in HTML too. In also has an SDK for AngularJS and is usually easy to use for any web application in any environment.

https://slashdb.com

It can simply buy you enough time to improve the web application of your choice, rather than putting that time in a data access code that will often be "invisible" to users.

Disclaimer: SlashDB is a product of my company.

0
source

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


All Articles