Skip to main content

.NET Core Web API + Third-Party API Integration – 20 Q&A

 

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

Popular posts from this blog

Top 20 .NET Developer Interview Questions & Answers 🚀 💡 Code Optimization, Performance, & Error-Free Coding Tips!

1️⃣ What is code optimization in .NET, and why is it important? ➡️ It’s about making code run faster, use less memory, and reduce bugs—leading to efficient and maintainable projects. 2️⃣ How do you find performance bottlenecks in .NET apps? ➡️ Use tools like Visual Studio Profiler , JetBrains dotTrace , or Application Insights to spot slow code and fix it early! 3️⃣ Best data structures for fast data retrieval in .NET? ➡️ Prefer  Dictionary  for lookups,  List  for indexed access, and  ConcurrentDictionary  for thread-safe scenarios. 4️⃣ Why limit excessive logging in production code? ➡️ Too much logging = slower app + increased costs. Log only what’s essential! 5️⃣ How does async programming (async/await) boost performance? ➡️ Keeps your app responsive by handling multiple tasks without blocking threads. 6️⃣ Steps to reduce unnecessary memory allocations? ➡️ Use structs, re-use objects (object pooling), and avoid big objects unless truly needed. 7️⃣ How ...

Top 30 Tricky C# Coding Interview Questions (With Solutions)

  1. Reverse a String Without Built-in Methods Q: Write a C# method to reverse a string without using built-in reverse functions. A: string Reverse(string input) {     char[] result = new char[input.Length];     for (int i = 0; i < input.Length; i++)         result[i] = input[input.Length - 1 - i];     return new string(result); } 2. Find Duplicates in an Integer Array Q: Detect and print duplicates in an integer array. A: void FindDuplicates(int[] arr) {     var seen = new HashSet<int>();     foreach (int num in arr) {         if (seen.Contains(num))             Console.WriteLine("Duplicate: " + num);         else             seen.Add(num);   ...

Infosys top 50 .net Interview Questions and Answers in details

.Net Core & CLR 1. What is .NET, and how does the CLR work? .NET is a developer platform from Microsoft providing a runtime (CLR), base class libraries, and tools to build apps for web, desktop, mobile, cloud, and more. The CLR (Common Language Runtime) manages code execution (MSIL), memory allocation, garbage collection, type safety, and exception handling, enabling multiple languages (C#, F#, VB) to run on the same runtime. 2. What are assemblies in .NET? An assembly is the basic unit of deployment and versioning, typically a DLL or EXE containing IL code, metadata, and resources. Assemblies can be private (application-local) or shared (in the Global Assembly Cache, typically strong-named). [1] 3. Difference between value types and reference types. Value types (struct, int, bool) are allocated typically on the stack or inline in objects, store the actual data, and are copied by value. Reference types (class, array, string) live on the heap, variables store reference...