How to reduce boilerplate code for web api calls? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am working with a ASP.NET MVC website and ASP.NET Web Api service. Current architecture looks like this
Browser => UI website => Web Api service => databases
The argument to split UI and Web Api was so that we can have several different UIs (Web, Mobile, Desktop, watches, etc) all calling intermediate service to get data. However, when I need to add a new api call i need to add quite a bit of plumbing boilerplate code (+ boilerplate tests which I dislike even more).
Browser => ajax
UI => controller and web api proxy client
Web API => controller and repository
database
I am thinking, it would have been easier to combine web api with UI, as I won't need to write additional controllers and proxy to call it, however I am not sure if this is the right way to go. We have about 20 controllers and 100 api calls written in C#. I am interested to know how other people use web api together with UI projects.
Should I merge Web Api project with UI project and what are the pros and cons of doing so?

Related

how to integrate angularjs with asp.net web api [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am new in angularjs and asp.net. I've searched a lot but did not get proper answer and more confused.
my problems are:
1) how to integrate angularjs application integrate with asp.net MVC web API using SQL server.
2) I got the solution for two projects like one is client second is a server so now first I starts server project as the startup project and then client project starts as the startup project and then performs API operation so my question is:
i) what happened when upload it to a global server.
ii) will I add both of projects one by one on server (server and client)?
my desire is to make it in one project and angular should be in html due to performance purpose so don't want to shifting as cshtml and also want some cshtml page for admin panel like (product upload etc)
I am looking for best approach kindly suggest me.
Dear Zeeshan it's not complicated.
As you mentioned angularjs manager client side of your project with MVC pattern and ASP.net web API makes your server side services as RESTFul. If you want develop both of server and client side it's up to you but Somehow you will get involved with both of them. In production you will have no problem with these, you must just deploy Asp.Net and angularjs play will play his role as a simple JavaScript library.
You can use this link as a sample.

ASP.net WEB API (MVC5) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
This question is regarding Web API. I have a Mobile and a ASP.NET MVC5 web application. These application will interact with same DB. I thought instead of writing the code twice, we can have a WEB Api which will interact with DB and return data to the applications.
My Web API should be in MVC5 project/ Solution or I should have this API in separate solution and expose that API to both the application?
I would suggest to keep your Web Api and MVC Application in a single project. Just create a folder in your controller, for example Data, and keep your Api controller here, which must be derived from ApiController.
Then add a WebApiConfig.cs file in your App_Start folder and change the route for your Api's. (You just need to copy your route code from your Api project, if you have already, and place here.)
Then in your Global.asax.cs file, in Application_Start event, call your route for Api. You just need to add this line of code,
GlobalConfiguration.Configure(WebApiConfig.Register);
Then add all the required references for Api's through Nuget to your project, For example System.Web.Http;
That's it! Hope you understand :)

Why you would choose ASP.NET MVC over SPA + ASP.NET WebAPI? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm asking this just to see experiences from others.
For most of the cases having ASP MVC web site is an overhead. At least for me it's much cleaner and easier to have WebAPI which responds with JSON and then you can attach either SPA application or Mobile app or whatever.
I have a feeling that if you are using ASP MVC controllers will not be controllers, but controllers full of the if conditions and some session bags which are hanging around. Views are combination of HTML and Razor which in most cases looks really ugly and full of "TODOs" ;)
I can understand if it's used in older projects and now we just need to maintain them. But when you are starting a new one, why you would choose ASP.NET MVC or any other similar framework?
In my opinion, it is all about your expectations - if you need REST you should take WebAPI of course, but in case of RPC Style Actions requirements in your project, MVC will be better choice
It depends on the resources available. If you have a team already that is doing all pure UI (all request/response to the backend is via a RESTful API), then you can have those team create the UI for you and you can focus on the API. These UI applications are mostly client-facing products.
But sometimes in your team there is a need to develop in-house or internal applications such admin/operations applications, and the UI requirement is not as sophisticated , the teams skillset is not heavy on UI, and there is a need to develop the application ASAP, then I would go with MVC.

which approach is best for GET,POST using Rest API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
i am using rest api to fetch and save the data in database using jquery or angularjs, but i want to ask you about which approach is best for doing this.
using jquery to post the data
using angularjs to post the data
using c# code behind to post the data using mvc.
performance and security wise which is best.
There is no 'best' way to do this, but I'd suggest implementing your RESTful API using ASP.NET Web API and then consuming that with AngularJS on the front-end (using the $http service). It's a pretty neat way of communicating with your APIs without having to navigate away from the page, as you would have to do if it was all implemented using ASP.NET MVC.
But then I suppose it depends what you're actually implementing, does it make sense to navigate away from a page after creating or updating something? If you're creating entities from a HTML form then it would make sense to navigate the user to a completely different page after creating/updating. But if you're doing something different like changing the order of entities in a list, consuming a RESTful API without navigating away from the page would make sense.

which one to use : Web Services or WCF Services [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
We have a c#net windows application. now our company decided to develop a web application using asp.net to support some of the windows application functionality on the world wide web.
so we are going to deploy some services in our windows application an let the web application to use them.
Which one is the better choice : deploying WCF services or Web services ?
Web Services is a name for services that are reachable over the web infrastructure. Classically that has meant SOAP services, but the last years REST and REST-style (JSON over HTTP but not employing full REST semantics) have grown more popular.
So first you have to choose what kind of API you want to expose: SOAP or JSON over HTTP.
Second, you need a suitable framework for implementing such a services for SOAP services WCF is the right choice. asmx services are deprecated. For JSON over HTTP you can use WCF, but WebApi is easier to work with.
WCF are more complex and powerful than ASMX. However, that also means it takes a lot more effort to write them and a lot more knowledge to handle them. ASMX are super easy to write. Unless you specifically need features in WCF, go with ASMX. That said, there's also the option of ASP.NET Web Api which is the most recent service framework. It's similar to ASMX but much smarter and nicer to work with. I would recommend Web Api if you can use it in your situation.

Categories