Generating a JS-client based on a ASP.NET WebAPI Controller

后端 未结 3 1580
忘掉有多难
忘掉有多难 2021-01-30 11:41

In modern web-projects that use RESTful API\'s we often see AJAX-calls like the one below littered around our JavaScript-files.

$.ajax({
    type: \"POST\",
             


        
3条回答
  •  星月不相逢
    2021-01-30 12:12

    I'm working on the Swagger open-source toolchain NSwag for .NET: With this tool you can generate the TypeScript client for a single or multiple Web API controllers.

    In the UI just

    1. Select the Web API DLL
    2. Select the controller classes
    3. Generate TypeScript client code (in your case, select the JQueryCallbacks or JQueryPromises template)

    Have a look at http://nswag.org

    FYI: TypeScript is a language which gets transpiled to JavaScript

提交回复
热议问题