Skip to main content
Any Framework

DotNet tool to generate Refit HTTP client types from ASP.NET Core API controllers.

Published
May 1, 2025
1y ago
Total Downloads
53.3K
53,313

Install

dotnet add package GenerateAspNetCoreClient.Refit --version 3.2.0

No framework information available.

README

Nuget Stand With Ukraine

GenerateAspNetCoreClient

DotNet tool to generate Refit HTTP client types from ASP.NET Core API controllers.

Prerequisites

Tool requires .NET 9 runtime installed, and it supports projects with ASP.NET Core 9 or 8.

Usage

Install dotnet tool from Nuget:

dotnet tool install GenerateAspNetCoreClient.Refit -g

Then execute the following in the directory with your Web project:

dotnet-generate-client MyApiProjectPath -o OutPath -n My.Client.Namespace

The tool will generate Refit interfaces based on the endpoints defined in your project. Please note that only .cs files are created, you still need to add the project file, with project references for models (if any needed), and Refit package reference.

Examples

Based on the following controller:

    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        [HttpGet]
        public async Task<ActionResult<IEnumerable<WeatherForecast>>> Get()
        {...
        }
        
        [HttpGet("{id}")]
        public async Task<WeatherForecast> Get(Guid id)
        {...
        }
    }

IWeatherForecastApi.cs file is created:

//<auto-generated />

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Refit;
using TestWebApi.Models;

namespace Test.Name.Space
{
    public interface IWeatherForecastApi
    {
        [Get("/WeatherForecast")]
        Task<IEnumerable<WeatherForecast>> Get();

        [Get("/WeatherForecast/{id}")]
        Task<WeatherForecast> Get(Guid id);
    }
}

Parameters

  -o, --out-path              Required. Relative out path for generated files.

  -n, --namespace             Required. Namespace for generated client types.

  --environment               ASPNETCORE_ENVIRONMENT to set during generation.

  --type-name-pattern         (Default: I[controller]Api) Pattern by which client types are named.

  --access-modifier           (Default: public) Access modifier used for generated clients.

  --add-cancellation-token    (Default: false) Add CancellationToken parameters to all endpoints.

  --use-query-models          (Default: false) Use query container type parameter (as defined in the endpoint) instead
                              of separate parameters.

  --use-api-responses         (Default: false) Use Task<IApiResponse<T>> return types for endpoints.

  --exclude-types             Exclude all controller types with substring in full name (including namespace).

  --exclude-paths             Exclude all endpoints with substring in relative path.

  --include-types             Include only controller types with substring in full name (including namespace).

  --include-paths             Include only endpoints with substring in relative path.

Changes from Previous Version

No structural changes between v3.1.0 and v3.2.0.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.