Advertisement

Networking & APIs interview questions and answers

7 Networking & APIs interview questions for .NET MAUI roles, each with a model answer, examples and likely follow-ups.

7 questions
Advertisement

7 questions

Q1 Beginner Save

How do you call a REST API in MAUI?

Use HttpClient (ideally via IHttpClientFactory) to send async requests, and System.Text.Json to deserialize responses. Always await calls off the UI thread and handle non-success status codes. Set base address and default headers once on the client.
var response = await _http.GetAsync("products");
response.EnsureSuccessStatusCode();
var products = await response.Content
    .ReadFromJsonAsync<List<Product>>();
Real-world example
A catalog page loads products from a JSON API and binds them to a CollectionView.
Likely follow-ups
  • Why use IHttpClientFactory? | How do you deserialize JSON?
HttpClient JSON Networking & APIs
Q2 Beginner Save

How do you check network connectivity before making a request?

Query Connectivity.Current.NetworkAccess (Internet, Local, None) and optionally ConnectionProfiles (WiFi, Cellular). Subscribe to ConnectivityChanged to react to changes. Use it to skip requests, show offline UI, or defer syncing on metered connections.
if (Connectivity.Current.NetworkAccess != NetworkAccess.Internet)
{
    await DisplayAlert("Offline", "Check your connection.", "OK");
    return;
}
Real-world example
Before syncing large data, an app warns the user and waits when only cellular or no connection is available.
Likely follow-ups
  • What is ConnectivityChanged? | How do you detect metered connections?
Connectivity Offline Networking & APIs
Q3 Intermediate Save

How do you handle JSON serialization efficiently in MAUI?

Use System.Text.Json with source-generated serialization (JsonSerializerContext) to avoid reflection, which improves performance and trims better for AOT. Configure options (camelCase, ignore nulls) once and reuse them. Source generation is especially valuable given MAUI's trimming and Native AOT direction.
[JsonSerializable(typeof(List<Product>))]
partial class ApiJsonContext : JsonSerializerContext { }

var products = JsonSerializer.Deserialize(json,
    ApiJsonContext.Default.ListProduct);
Real-world example
Switching to source-generated JSON removes reflection warnings under trimming and speeds up parsing large payloads.
Likely follow-ups
  • Why source generation over reflection? | How does it help trimming?
JSON Performance & Optimization Networking & APIs
Q4 Intermediate Save

How do you implement resilient HTTP calls (retries, timeouts) in MAUI?

Wrap HttpClient with Polly via IHttpClientFactory's AddPolicyHandler to add retry with backoff, circuit breakers, and timeouts. This handles transient failures common on mobile networks without scattering try/catch and manual retry loops.
builder.Services.AddHttpClient<IApiClient, ApiClient>()
    .AddTransientHttpErrorPolicy(p =>
        p.WaitAndRetryAsync(3, r => TimeSpan.FromSeconds(Math.Pow(2, r))));
Real-world example
Flaky mobile connections recover automatically as failed requests retry with exponential backoff instead of surfacing errors immediately.
Likely follow-ups
  • What is a circuit breaker? | Where do you register Polly policies?
HttpClient Resilience Networking & APIs
Q5 Intermediate Save

How do you keep API calls off the UI thread and update the UI safely?

Await async HttpClient calls—they run I/O off the UI thread already. When you must marshal a result back to the UI from a non-UI context, use MainThread.BeginInvokeOnMainThread. Binding updates from async view-model code are marshaled by MAUI, but explicit UI mutations must be on the main thread.
var data = await _api.GetAsync();      // off UI thread
MainThread.BeginInvokeOnMainThread(() => Items.Add(data));
Real-world example
A background refresh fetches data without freezing the UI, then updates an observable collection on the main thread.
Likely follow-ups
  • When do you need MainThread.BeginInvokeOnMainThread? | Are bindings auto-marshaled?
Threading Performance & Optimization Networking & APIs
Q6 Advanced Save

How do you implement authentication token refresh transparently for API calls?

Use a DelegatingHandler in the HttpClient pipeline that attaches the access token, detects 401 responses, refreshes the token (serialized with a lock/semaphore to avoid stampedes), and retries the request. Store tokens in SecureStorage. This centralizes auth so callers stay unaware.
class AuthHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage req, CancellationToken ct)
    {
        req.Headers.Authorization = new("Bearer", await _tokens.GetAsync());
        var res = await base.SendAsync(req, ct);
        // on 401: refresh + retry
        return res;
    }
}
Real-world example
Expired tokens refresh silently mid-session so users are never bounced to the login screen during normal use.
Likely follow-ups
  • How do you prevent concurrent refreshes? | Where do you register the handler?
Authentication HttpClient Security
Q7 Advanced Save

How do you handle real-time updates (WebSockets/SignalR) in a MAUI app?

Use the SignalR client (Microsoft.AspNetCore.SignalR.Client) or ClientWebSocket for push updates. Start the connection in a service, subscribe to hub events, and marshal updates to the UI thread. Manage the connection lifecycle with app state—reconnect on resume, stop or background appropriately on sleep.
var hub = new HubConnectionBuilder()
    .WithUrl("https://api.example.com/chat").WithAutomaticReconnect().Build();
hub.On<string>("Receive", msg =>
    MainThread.BeginInvokeOnMainThread(() => Messages.Add(msg)));
await hub.StartAsync();
Real-world example
A chat app receives messages instantly over SignalR and reconnects automatically after transient drops.
Likely follow-ups
  • How do you tie connections to app lifecycle? | What is WithAutomaticReconnect?
SignalR Real-time App Lifecycle