Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use my Web Api project from other projects inside my solution?

Tags:

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.

like image 212
PersuitOfPerfection Avatar asked Jul 10 '14 18:07

PersuitOfPerfection


People also ask

How can I call one API from another API in net?

You could use . Net classes like HttpClient, WebClient or WebRequest to call one service from another.

How do I add a Web API to an existing ASP.NET project?

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.


1 Answers

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.

like image 57
mohsen dorparasti Avatar answered Sep 25 '22 15:09

mohsen dorparasti