dotnet-refit-http

.NET HTTP Communication with Refit & Resilience

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "dotnet-refit-http" with this command: npx skills add marcelodanieltoledo/dotnet-refit-http/marcelodanieltoledo-dotnet-refit-http-dotnet-refit-http

.NET HTTP Communication with Refit & Resilience

Standardized approach for consuming external APIs using Refit and Microsoft.Extensions.Http.Resilience.

Detail Files

File Content

interfaces.md How to define API contracts, attributes, and return types (ApiResponse<T> ).

usage.md Best practices for consuming ApiResponse<T> , handling errors, and reading headers.

resilience.md Configuring AddStandardResilienceHandler and custom Polly policies.

dtos.md Creating immutable record DTOs with proper JSON mapping.

configuration.md DI registration, Auth handlers, and RefitSettings.

testing.md Patterns for Unit Testing (Moq) and Integration Testing (MockHttp).

Core Principles

  • Refit Interfaces: Define API contracts as interfaces.

  • Immutable DTOs: Use record for all request/response models.

  • Resilience: Apply standard resilience handlers (Polly) via DI.

  • Typed Clients: Always register clients with AddRefitClient<T>() .

  • No Exceptions: Prefer ApiResponse<T> over catching exceptions for flow control.

Quick Start

  1. Add Packages

dotnet add package Refit.HttpClientFactory dotnet add package Microsoft.Extensions.Http.Resilience

  1. Define the Interface

using Refit;

public interface IExternalUserApi { [Get("/users/{id}")] Task<ApiResponse<UserResponse>> GetUserAsync(string id, CancellationToken ct); }

  1. Register in Program.cs

builder.Services .AddRefitClient<IExternalUserApi>() .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.example.com")) .AddStandardResilienceHandler();

MANDATORY Checklist

Component ✅ DO THIS ❌ AVOID THIS

Client AddRefitClient<T>()

new HttpClient()

Models public record Name(string Val);

public class Name { get; set; }

Resilience .AddStandardResilienceHandler()

Manual Policy.Handle<T>()...

Async Pass CancellationToken

.Result or .Wait()

Config BaseAddress in DI Hardcoded URLs in Client

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

image-gen

Generate AI images from text prompts. Triggers on: "生成图片", "画一张", "AI图", "generate image", "配图", "create picture", "draw", "visualize", "generate an image".

Archived SourceRecently Updated
General

explainer

Create explainer videos with narration and AI-generated visuals. Triggers on: "解说视频", "explainer video", "explain this as a video", "tutorial video", "introduce X (video)", "解释一下XX(视频形式)".

Archived SourceRecently Updated
General

asr

Transcribe audio files to text using local speech recognition. Triggers on: "转录", "transcribe", "语音转文字", "ASR", "识别音频", "把这段音频转成文字".

Archived SourceRecently Updated
General

axure-prototype-generator

Axure 原型代码生成器 - 输出 JavaScript 格式 HTML 代码,支持内联框架直接加载可交互原型

Archived SourceRecently Updated