-
Notifications
You must be signed in to change notification settings - Fork 90
WebApi Proxy Provider
faniereynders edited this page Jan 15, 2014
·
4 revisions
Extend your ASP.NET Web API service by installing this package from NuGet:
Install-Package WebApiProxyNote: This package requires the core libraries of ASP.NET Web API (version 5 or higher)
This extension provides a proxy endpoint in your service as /api/proxies that serves JavaScript and service metadata.
Given a Person API on the server:
public class PeopleController : ApiController
{
public Person[] Get() {
}
public Person Get(int id) {
}
}allows you to use it like this in JavaScript on the client:
$.proxies.person.get()
.done(function(people) {
//do something with people
});
$.proxies.person.get(2)
.done(function(person) {
//do something with person
});Simply reference the proxy endpoint provided inside your HTML and you're good to go:
<script src="/api/proxies" type="text/javascript"></script>