Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating a JS-client based on a ASP.NET WebAPI Controller
    primarykey
    data
    text
    <p>In modern web-projects that use RESTful API's we often see AJAX-calls like the one below littered around our JavaScript-files.</p> <pre><code>$.ajax({ type: "POST", url: myapp.baseUrl + 'Api/Note', data: ko.mapping.toJSON(note), contentType: 'application/json', }).done(function (response) { // do something }).fail(function (jqxhr) { // do something else }); </code></pre> <p>I love WebAPI, I love Knockout and I love tying the two together. However these AJAX-calls are quite verbose and contain all kinds of details that I am not really interested in. So instead, I create a wrapper around these methods:</p> <pre><code>myapp.api.saveNote(note) </code></pre> <p>However this still requires me to actually write a wrapper containing the AJAX-call. I was wondering if you could actually <strong>generate these wrappers</strong>. In essence, I would be generating a JS-based client for my WebAPI, similar to how Java and .NET can generate clients based on WSDL's.</p> <ol> <li>Has this been done before?</li> <li>Are there other ways to tie ASP.NET WebAPI and JavaScript together without writing a bunch of AJAX boilerplate code?</li> <li>In other words, are there frameworks for creating JS-interfaces based on server-side interfaces like ASP.NET WebAPI?</li> </ol> <p>I've already looked at amplifyJS but this only partially solves the problem. I am looking for a solution that actually creates an interface based on the WebAPI-controllers in my solution. If this does not exist, I will start tinkering myself. I've already got an idea for a <code>WebAPIClientGenerator</code> that uses reflection to iterate over all <code>ApiController</code>'s.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload