Skip to content

Fetch JSON data from an external API and return top records in a MVC web application.

License

Notifications You must be signed in to change notification settings

Lidiadev/external-api-client

Repository files navigation

external-api-client

Build Status

RealEstate is an ASP.NET Core MVC web application with the following feature:

  • get the top 10 real estate agents with the most properties.

Design considerations:

  • In order to get the top 10 real estate agents, the PropertyService is making calls to the PartnerAPI.
  • Because the external API is returning a paginated response, all the pages have to be retrieved to be able to get the top 10 agents.
  • In order to minimize the data stored in memory, every time a partial list is retrieved, the list of the top 10 is computed in place. That means that there won't be more than the size of the page agents stored in memory.
  • Cache is used to improve performance.
  • Retry pattern is used with Polly.

Further improvements:

  • use Redis Cache and a worker roler to process the data and add it to the cache. The GET request will always hit the cache instead of performing expensive requests which take some time to be processed.
  • deployment in Docker.
  • run the AT against a mock API.

Prerequirements

  • Visual Studio 2019
  • .NET Core 3.0.1 SDK

Frameworks Used

  • .NET Core 3.0
  • NUnit

Solution Overview

RealEstate.Domain

  • DTOs

RealEstate.Presentation

  • ASP.NET Core Web MVC
  • Application contracts and implementation.

RealEstate.UnitTests

  • Unit tests for all layers.

RealEstate.IntegrationsTests

  • Integration tests for getting the agents list.

Continuous Integration

Travis CI has been used to run the tests. Each pushed commit runs the unit tests.

How to Run the Application

    "PartnerAPI": {
        "APIKey": "TBR"
    },
    "BaseUrls": {
        "PartnerAPI": "TBR"
    }
  • Replace the SalesObjectsPath the Constants file:
/// <summary>
/// The path for objects which are on sale.
/// </summary>
public const string SaleObjectsPath = "TBR";

Polly

Polly is a library that provides resilience and transient-fault handling capabilities. Polly has been used to define a Retry policy for the HttpClient:

 services.AddHttpClient<ApiClient>(x => 
        {
            x.BaseAddress = new Uri(baseUrls.PartnerAPI); 
        })
        .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
        {
            TimeSpan.FromSeconds(1),
            TimeSpan.FromSeconds(5),
            TimeSpan.FromSeconds(10)
        }));

Memory Cache

Memory Cache has been used to improve perfomance. The cached item has a sliding expiration and an absolute expiration.

How To Run Unit Tests

  • Open solution in Visual Studio 2019
  • Open Test Explorer
  • Run the Order.UnitTests tests.

How To Run Integration Tests

  • Open solution in Visual Studio 2019
  • Open Test Explorer
  • Run the Order.IntegrationTests tests.

Libraries Used for Testing

  • Moq - mocking framewework used to mimic the behavior of classes and interfaces
  • FluentAssertions

About

Fetch JSON data from an external API and return top records in a MVC web application.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published