-
Notifications
You must be signed in to change notification settings - Fork 91
WebApiProxy on the client side
Fanie Reynders edited this page Jan 18, 2016
·
4 revisions
This extension provides a proxy endpoint in your service (with /api/proxies
as the default) that serves a JavaScript client (using JQuery) and/or service metadata.
The following examples will assume a Person API on the server:
public class PeopleController : ApiController
{
public Person[] Get() {
}
public Person Get(int id) {
}
}
Simply reference the proxy endpoint provided inside your HTML and you're good to go:
<script src="/api/proxies" type="text/javascript"></script>
It allows you to use it in JavaScript like this:
$.proxies.person.get()
.done(function(people) {
//do something with people
});
$.proxies.person.get(2)
.done(function(person) {
//do something with person
});
This functionality was adopted from ProxyApi - kudos to Stephen Greatrex :)