maui-rest-api

Configure HttpClient and JSON serialization for .NET MAUI REST API consumption.

Updated Nov 27, 2025
One-click install
npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-rest-api-seydakaratekeli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-rest-api
Source: https://github.com/seydakaratekeli/KamPay3/tree/main/KamPay/.github/skills/maui-rest-api%20-%20Kopyala
Command: npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-rest-api-seydakaratekeli

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill documents best practices and common gotchas for consuming REST APIs from .NET MAUI applications, helping prevent socket exhaustion, UI deadlocks, incorrect JSON deserialization, and platform-specific networking failures.

Core Features & Use Cases

  • HttpClient lifecycle management: guidance to register HttpClient as a singleton or use IHttpClientFactory to avoid socket exhaustion.
  • Async and error handling: use async/await correctly, check status codes before deserializing, and catch HttpRequestException and JsonException.
  • Serialization and DI patterns: configure JsonSerializerOptions with camelCase and register API services via interfaces for testability and separation of concerns.
  • Full CRUD and platform notes: patterns for GET/POST/PUT/DELETE, emulator loopback addresses (Android 10.0.2.2 vs iOS localhost), and clear-text HTTP configuration for local development.

Quick Start

Register a singleton HttpClient and your API service in DI, configure JsonSerializerOptions with camelCase, and call the provided async CRUD methods while handling HttpRequestException and JsonException.

Frequently Asked Questions about maui-rest-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does creating a new HttpClient per request cause socket exhaustion in .NET MAUI?

HttpClient socket exhaustion occurs because sockets linger after disposal. In .NET MAUI, you prevent socket exhaustion by registering HttpClient as a singleton or using IHttpClientFactory to reuse HTTP message handlers.

How do I handle JSON deserialization errors when consuming a REST API in .NET MAUI?

To handle JSON deserialization errors during REST API consumption, catch JsonException and HttpRequestException. You should also configure JsonSerializerOptions with camelCase and check HTTP status codes before attempting to deserialize the response.

What's the best way to configure HttpClient for dependency injection in .NET MAUI?

The best way to configure HttpClient for dependency injection in .NET MAUI is registering it as a singleton or using IHttpClientFactory. This pattern ensures proper handler lifecycle management and prevents socket exhaustion.

How do I configure clear-text HTTP traffic for local API testing in .NET MAUI?

To configure clear-text HTTP traffic for local API testing in .NET MAUI, update platform-specific networking configurations. Use Android 10.0.2.2 for emulator loopback and adjust iOS settings to allow local HTTP connections during development.

Does .NET MAUI support async CRUD operations with REST APIs?

.NET MAUI supports async CRUD operations with REST APIs by using async/await patterns. You can implement GET, POST, PUT, and DELETE requests using HttpClient while properly handling HttpRequestException to avoid UI deadlocks.

Why is my JSON deserialization returning incorrect data from a REST API in .NET MAUI?

JSON deserialization returns incorrect data when JsonSerializerOptions mismatch the API payload. Configure camelCase options in .NET MAUI and check HTTP status codes before deserializing to ensure valid JSON is processed.