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

test_skill

import json import tkinter as tk from tkinter import messagebox, simpledialog

Archived SourceRecently Updated
General

错敏信息检测

1. 安装https://clawhub.ai/xxxx/sensitive-check-skill 这个技能 2. 调用错敏信息检测技能,传入参数 userKey=xxxx,content=xxxx

Archived SourceRecently Updated
General

neo

Browse websites, read web pages, interact with web apps, call website APIs, and automate web tasks. Use Neo when: user asks to check a website, read a web page, post on social media (Twitter/X), interact with any web app, look up information on a specific site, scrape data from websites, automate browser tasks, or when you need to call any website's API. Keywords: website, web page, browse, URL, http, API, twitter, tweet, post, scrape, web app, open site, check site, read page, social media, online service.

Archived SourceRecently Updated
General

image-gen

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

Archived SourceRecently Updated