MVC3 - Is there a proper name for this type of service pattern? - asp.net-mvc-3

I am using Controllers as services to return HTML/JSON. Is there a proper technical name for what I am doing here?
A user triggers an event
Perform AJAX GET
Request handled by Controller
Return HTML/JSON
Populate front end HTML object(s) with result
This strikes me as a service oriented design. It has the benefit of behaving like a RIA app. I have heard of "RESTFUL" services, but I don't know if this fits the bill.

I use the exact same schema in our main app. It's a subset of Service Oriented Design/Architecture. You actually use "services", such as: Login, CreateBlogPost, DeletePicture, Register, Connect and so on. But I believe that services serve broader goals. For example, exposing an API, which could be essentially accessed in the same manner you describe but respond to more HTTP verbs other than GET: POST, HEAD, PUT, DELETE. This is a RESTful service, as you mentioned.
So, to answer your question, the schema you describe plays a role in a good architected RIA. I don't believe it has a unique name of its own (besides being part of SOA).

Related

Calling a WebApi as a class instance

This is more of a design question than a problem. So here's the scenario, you have an asp.net 5 application with a webapi controller and it provides data to many types of clients: web, ios, java apps, etc. Let's say that one of those clients happens to be an mvc controller within the same web host and visual studio solution as the webapi.
What are the ramifications of calling into the webapi as a class instance, instead of doing what the other client types are doing--which is to make a rest based network call? The obvious benefits are eliminating the over head of a network call and eliminating the serialization. But I wanted to know what some of the possible negatives could be. Has anyone done this before?
The easy solution could be that you could extract that logic to a separate assembly... let say a "Business Logic Layer" so that both WebApi and MVC could access it.
This has the downside, that you will not be able to have MVC and WebApi separate. I mean, using WebApi as a single data interface could allow you to host MVC app separately from where the WebApi is hosted... but the approach in the first paragraph will couple both proyects and will force you to host them together to have access to the data.
If you call the class directly any work done by the HTTP pipeline won't be done. So your API class won't have access to the HttpContext for example.
Also none of the security or Http related annotations (attributes) will work, so your MVC controller may need to deal with that.

BreezeJS - Is there any way to use old style 'One controller to rule them all' with OData Web API?

I would like to expose the SQL Server Views via OData Web API but I don't want to create separate controllers for each views as there are too many of them and they will only accept GET verb for all the views.
I thought I can achieve this using BreezeController but it looks like I cannot as it is obsolete now (The package which has BreezeController attribute is marked as obsolete).
Is there any way to achieve this with OData Web API that works with BreezeJS?
The [BreezeController] attribute is not obsolete. In fact, it is central to the "happy path" Web API controllers you see in the Breeze samples. I wonder what lead you to think otherwise? What package are you using?
I'm referring to the ASP.NET Web API!
The ASP.NET Web API OData is a different matter. Despite "Web API" in the name, that is almost a completely different approach to server development with its own behaviors and wire format. It does not use the [BreezeController] attribute and never has.
I'm not sure what you meant by "view" in your phrase, "separate controllers for each view". I think you mean what I would call "type". For example, in OData you'd expect a "Product" endpoint for your Product entity type.
AFAIK, the Web API OData approach demands a separate controller per type. That's what Microsoft's Mike Wasson says in his tutorial. He writes ...
A controller is a class that handles HTTP requests. You create a separate controller for each entity set in your OData service.
BreezeJS supports Web API OData too ... although there are limitations imposed by the current Microsoft implementation that may give you pause.
We are working through these with the OData team and hope to have better news in the coming months.

Nice approach for redirecting request to correct application instance?

This is not a question but an effort to get the comments from experts out there.
Let’s consider, that there are 2 web applications, namely, “SPRING-WEB-APP-1” & “SPRING-WEB-APP-2”.
Now, both of these applications are supposed to be accessible by their own sets of users (i.e. “SPRING-WEB-APP-2” shouldn’t be accessible by “SPRING-WEB-APP-1-USERS” and vice versa).
Both applications are deployed on different instances of application servers as 2 separate WARS.
All HTTP requests shall land in “SPRING-WEB-APP-1” and requests shall be redirected/forwarded(based on the “Type Of Users”) to either of the one application mentioned above.
What will be an extensible and modular solution for this?
Well, I am thinking to create a Spring controller (named as “RequestRedirectionController”) for all incoming HTTP requests.
Said controller shall be responsible to test the type of user from which request came and will redirect request to either “SPRING-WEB-APP-1” or “SPRING-WEB-APP-2”, through JSP forward.
Any comments shall be highly appreciated?

Laravel 4 Route::dispatch overhead

I'm working on a web application that need to expose Json API for external apps and I'm planning to do an API centric architecture.
So basicly, the app will juste contains view/controllers for the web interface. the controllers will use Route::dispatch to create a request to the api part of the site (another controller in a package, but in the same laravel installation), then parse the result, and create view accordingly.
So I'm wondering what are the drawbacks, performance wise, of using this sort of architecture?
If each controller is writing the logic to internally dispatch another request then I'd consider abstracting that away from the controller and in to your own dispatcher. I doubt there would be a huge performance overhead. The application (as far as I know) doesn't get booted twice so you don't have to worry about that.
The only thing you need to be aware of is the input for the main request being used. Something you should take into account inside your dispatcher. Refer to this answer for more information.
You can also read more on consuming your own API.

Designing Web services for AJAX Consumption

We are in the process of designing/creating restful web services that will be consumed client side using XHR calls from various web pages. These web pages will contain components that will be populated by the data retrieved from the web services.
My question is, is it best to design the return data of the web services to match specifically what the client side components will require for each page? Therefore, only one XHR call will be required to retrieve all the data necessary to populate a specific AJAX component or to update a specific page. Or is it more advisable to develop generic web services, that match for instance a database schema, and will require multiple XHR calls client side to retrieve all the data to populate an AJAX component? The second approach seems to lead to some messy coding to chain calls together to retrieved all the data required before updating an AJAX component.
Hopefully this makes sense.
You should always design services based on what they are to provide. Unless you need a service that retrieves rows from the database, don't create one. You may find you need a service that returns complete business entities - they may be in multiple tables.
Or, you may just need a service to provide data for UI controls. In that case, that's what you should do. You may later find that two operations are returning almost the same data, so you may refactor that into one operation that returns the data for both.
My general rule of thumb is to do what ever is the smallest to transmit over the ajax call. In theory, the more data that is sent to the client the slower the update process. This, of course, would necessarily mean specific services for specific pages.

Resources