zijianhuang / webapiclientgen

Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
MIT License
167 stars 38 forks source link

Add Refit Support #128

Open startewho opened 1 year ago

startewho commented 1 year ago

This PR add the Refit Support. Refit is a library heavily inspired by Square's Retrofit library, and it turns your REST API into a live interface:

public interface IGitHubApi
{
    [Get("/users/{user}")]
    Task<User> GetUser(string user);
}

Add the Refit Client File by this setting

{
  "ApiSelections": {
    "ExcludedControllerNames": [
      "DemoWebApi.Controllers.Home"
    ],

    "DataModels": [
            {
                "AssemblyName": "DemoWebApi.DemoDataCore",
                "CherryPickingMethods": 3
            },

            {
                "AssemblyName": "DemoCoreWeb",
                "CherryPickingMethods": 1
            }
        ],
    "CherryPickingMethods": 0
  },

  "ClientApiOutputs": {
    "FileName":"WebApiClientRefit.cs",
    "ContainerNameSuffix":"",
    "ClientLibraryProjectFolderName": "..\\..\\DemoCoreWeb.ClientApi",
    "CamelCase": true,
    "CSClientNamespaceSuffix": "Refit.Client",
    "UseEnsureSuccessStatusCodeEx": false,
    "DataAnnotationsEnabled": true,
    "DataAnnotationsToComments": true,
    "HandleHttpRequestHeaders": true,
    "GenerateBothAsyncAndSync ":false,
    "CancellationTokenEnabled": true,
    "DecorateDataModelWithDataContract": true,
    "DataContractNamespace": "http://fonlowdemo.com/2020/09",
    "DecorateDataModelWithSerializable": true,
    "IEnumerableToArray": false,
    "MaybeNullAttributeOnMethod": true,
    "NotNullAttributeOnMethod": true,
    "UseSystemTextJson": true,
    "UseRefit":true,
    "Plugins": [

    ]
  }
}

Btw, refit support upload files also。 It's the first time i use the codedom,it seems lack a lot skills with your great the source code.

zijianhuang commented 3 months ago

What are the benefits to client programmers to use refit and its httpClient construction?