Daniel Billingham
Daniel Billingham

Reputation: 1411

Integrating Service stack with MVC and AngularJs

Using web.API with MVC seems very easy to setup, you leave the WebApiConfig.cs as default, create a new web.API controller, and then in your javascript you can call $http.get("api/...").

I want to be able to do the same using service stack instead of web.API. What makes it slightly more difficult is that the service stack api is in its own project. At the minute I can call the endpoints within MVC using the jsonServiceClient. However calling client side with Angular requires me to call the full FQDN which causes cross site scripting issues.

How can I configure my MVC project so that I can call my service stack endpoints from AngularJs's $http.get method like this:

$http.get("api/...")

rather than:

$http.get("http://localhost:2540/api/...")

Upvotes: 1

Views: 197

Answers (1)

ohiodoug
ohiodoug

Reputation: 1513

You can accomplish this by creating an alias in IIS under your web project and naming it API and pointing to your ServiceStack project.

You may run into issues in the future with this if you need to scale out your solution, but as long as you don't need to do that, you should be ok.

Upvotes: 2

Related Questions