GenerateAspNetCoreClient.Refit
2.0.0
See the version list below for details.
dotnet tool install --global GenerateAspNetCoreClient.Refit --version 2.0.0
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local GenerateAspNetCoreClient.Refit --version 2.0.0
#tool dotnet:?package=GenerateAspNetCoreClient.Refit&version=2.0.0
nuke :add-package GenerateAspNetCoreClient.Refit --version 2.0.0
GenerateAspNetCoreClient
DotNet tool to generate Refit HTTP client types from ASP.NET Core API controllers.
Prerequisites
Tool requires .NET 8 runtime installed, and it supports projects with ASP.NET Core 8, 7 or 6.
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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
2.1.0 | 2,774 | 1/10/2024 |
2.0.0 | 297 | 12/1/2023 |
1.1.0 | 5,197 | 12/16/2022 |
1.0.0 | 869 | 11/12/2022 |
0.8.0 | 3,471 | 8/23/2022 |
0.7.0 | 480 | 6/15/2022 |
0.6.0 | 504 | 4/16/2022 |
0.5.0 | 383 | 11/22/2021 |
0.4.0 | 327 | 8/3/2021 |
0.3.0 | 460 | 2/28/2021 |
0.2.0 | 418 | 12/5/2020 |
0.0.5 | 434 | 10/19/2020 |
0.0.4 | 594 | 7/8/2020 |
0.0.3 | 424 | 7/8/2020 |
0.0.2 | 472 | 6/29/2020 |
0.0.1 | 492 | 3/29/2020 |