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 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);   ...

Ace Your .NET Core Coding Interview: Top 20 Algorithmic & Problem-Solving Questions

 Beyond knowing the ins and outs of .NET Core, a successful technical interview often hinges on your ability to solve fundamental coding problems. These questions test your logical thinking, algorithm design, and grasp of basic data structures. This blog post provides 20 essential coding interview questions, complete with explanations and example approaches in C#, to help you shine in your next .NET Core technical assessment. 1. Reverse a String Without Built-in Functions Explanation: A classic that tests your understanding of loops and string manipulation. Question: Write a C# method to reverse a given string without using built-in Reverse() or ToArray() methods. Answer: C# public string ReverseString ( string input ) { if ( string .IsNullOrEmpty(input)) { return input; } char [] charArray = input.ToCharArray(); int left = 0 ; int right = charArray.Length - 1 ; while (left < right) { // Swap characters char...

Cracking the Code: Your Guide to the Top 60 C# Interview Questions

So, you're gearing up for a C# interview? Fantastic! This powerful and versatile language is a cornerstone of modern software development, and landing that C# role can open up a world of exciting opportunities. But navigating the interview process can feel like traversing a complex codebase. Fear not! We've compiled a comprehensive list of the top 60 C# interview questions, complete with detailed answers, to help you ace your next technical challenge. Whether you're just starting your C# journey or you're a seasoned pro looking to brush up your knowledge, this guide has something for you. We've broken down the questions into three levels: Beginner, Intermediate, and Advanced, allowing you to focus on the areas most relevant to your experience. Let's dive in and equip you with the knowledge you need to shine! Beginner Level (1–20) 1. What is C#? C# is a modern, object-oriented programming language developed by Microsoft as part of its .NET platform. It is design...