Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CatFacts Recruitment Task

Simple ASP.NET Core Web API created as a recruitment task.

The application retrieves a random cat fact from:

https://catfact.ninja/fact

Each retrieved response is appended as a new line to a local .txt file.

Technologies

  • .NET 10
  • ASP.NET Core Web API
  • Dependency Injection
  • HttpClientFactory
  • xUnit
  • Moq

Endpoint

GET /api/catfacts

Example response:

{
  "fact": "Cats sleep for around 16 hours a day.",
  "length": 41
}

Each response is also appended to:

CatFacts.Api/data/catfacts.txt

Configuration

The external API URL, timeout and file path are stored in appsettings.json.

Example:

{
  "CatFactApi": {
    "BaseUrl": "https://catfact.ninja/",
    "TimeoutSeconds": 10
  },
  "FileStorage": {
    "Path": "data/catfacts.txt"
  }
}

Running the project

dotnet restore
dotnet build
dotnet run --project CatFacts.Api

Then call:

GET /api/catfacts

Tests

Run tests with:

dotnet test

The project contains a unit test for CatFactService using Moq.

Technical decisions

  • HttpClientFactory is used for communication with the external API.
  • CancellationToken is propagated through the request flow.
  • SemaphoreSlim protects concurrent writes to the local file.
  • ILogger<T> is used for structured logging.
  • IExceptionHandler and ProblemDetails provide centralized error handling.
  • Configuration values are stored in appsettings.json.

The project intentionally does not use CQRS, MediatR, a database or additional architectural layers because they are not required for this small use case.

About

Recruitment task implemented using ASP.NET Core Web API. The application retrieves random cat facts from: https://catfact.ninja/fact and stores received data in a local text file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages