I am developing a ASP.NET Web Api and a ASP.NET Website. The website will make use of the Web Api and a mobile app will also be using the Web Api via REST.
Developing these two separately is going fine, however I am now at the stage where I would like to start testing the Web Api from the Website, ideally all from within visual studio. For instance, I have a page where I have a form, that when completed would call my Web Api to add a user to the database.Uploading these online for testing is naturally out of the question.
So what is the best practice here? Can you simply reference the Web Api from within the Website project (Aspx) or is there another way to go about this.
You could use . Net classes like HttpClient, WebClient or WebRequest to call one service from another.
Create the Model and Controller This tutorial uses the same model and controller classes as the Getting Started tutorial. Next, add a Web API controller to the project., A controller is the object that handles HTTP requests for Web API. In Solution Explorer, right-click the project. Select Add New Item.
Access to Web API controllers and actions are based on urls. So now that they are on separate projects you need to run both projects at the same time to make your API available for MVC project.
and by the way you should enable CORS for your web api project so that you can access it from your MVC project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With