Skip to content

WebApiProxy on the client side

Fanie Reynders edited this page Jan 18, 2016 · 4 revisions

Usage

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) {
    }
}

JavaScript client

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 :)

Clone this wiki locally