Tired of generic .NET interview questions?
Let's talk real-world – integrating your Web API with Stripe, Razorpay, Twilio,
SendGrid, or even OpenAI.
Here are 20 essential interview questions (with answers) on .NET Core Web API
integration with third-party APIs that will help you land interviews, grow
skills, and impress clients.
Q1: How do you call a third-party API in .NET Core Web
API?
A: Using HttpClient, injected via DI.
public class MyService
{
private readonly HttpClient
_httpClient;
public MyService(HttpClient
httpClient)
{
_httpClient = httpClient;
}
public async Task<string>
GetDataAsync()
{
var response = await
_httpClient.GetAsync("https://api.example.com/data");
return await
response.Content.ReadAsStringAsync();
}
}
Q2: How do you register HttpClient in Startup.cs or
Program.cs?
A: services.AddHttpClient<IMyService,
MyService>();
Q3: What is a DelegatingHandler?
A: It's middleware for HttpClient to handle
cross-cutting concerns like logging, authentication, retry policies.
Q4: How do you send headers (e.g., Authorization) with a
request?
A:
_httpClient.DefaultRequestHeaders.Authorization =
new
AuthenticationHeaderValue("Bearer", token);
Q5: How do you handle JSON responses from third-party
APIs?
A: Use System.Text.Json or Newtonsoft.Json:
var data = JsonSerializer.Deserialize<MyDto>(responseBody);
Q6: How do you send a POST request with a JSON body?
A: var content = new
StringContent(JsonSerializer.Serialize(myModel), Encoding.UTF8,
"application/json");
var response = await
_httpClient.PostAsync("url", content);
Q7: How to retry failed requests automatically?
A: Use Polly with HttpClientFactory:
services.AddHttpClient("API").AddPolicyHandler(
HttpPolicyExtensions.HandleTransientHttpError().RetryAsync(3));
Q8: How do you integrate with Stripe/PayPal in .NET Core?
A: Use official SDKs (e.g., Stripe.net) or
REST APIs. Always validate webhooks and secure secrets.
Q9: How do you securely store API keys/secrets?
A: Store in appsettings.json, Environment
Variables, or use Azure Key Vault.
Q10: How to consume a SOAP service in .NET Core Web API?
A: Use Connected Services in Visual Studio
or tools like dotnet-svcutil to generate client proxies.
Q11: What is a Webhook, and how to consume it?
A: Webhook is an HTTP callback. You create
a POST endpoint to receive and process incoming webhook requests.
Q12: How do you handle timeouts in HttpClient?
A: httpClient.Timeout =
TimeSpan.FromSeconds(30);
Q13: How do you log external API calls?
A: Use middleware, ILogger, or tools like
Serilog, Seq, or Application Insights.
Q14: How do you consume paginated APIs?
A: Keep calling API while nextPageUrl or
hasMore flag exists in the response.
Q15: How do you handle rate limiting from a third-party
API?
A: Respect Retry-After headers, use Polly
to delay or fallback.
Q16: How do you test external API integrations locally?
A: Use Postman, Swagger, or mock services
with WireMock.Net or Moq.
Q17: How do you use third-party authentication (Google,
Microsoft) in .NET Core Web API?
A: Use OAuth/OpenID Connect libraries like
Microsoft.AspNetCore.Authentication.Google with JWT validation.
Q18: How to handle large data downloads from an API?
A: Stream the response using
HttpClient.GetStreamAsync() instead of loading entire content in memory.
Q19: How do you use Swagger to document third-party API
consumption?
A: Add comments and models that explain
outbound calls; mention integration points in endpoint descriptions.
Q20: What to consider when integrating multiple
third-party APIs in a single Web API?
A: Timeout and retry settings, Circuit
breaker pattern, Logging & monitoring, Configurable base URLs, Consistent
DTO models.
Comments
Post a Comment