Skip to content

rustamhajiyev/best-stories

Repository files navigation

Best Stories API

This project is a RESTful API designed to fetch and deliver detailed information about the top n stories, sorted by their score in a descending order, from the Hacker News API. It’s built on .NET 9.0 and leverages Docker for containerization, while the testing framework uses xUnit in conjunction with TestContainers to ensure robust and isolated test environments.

Key Project Features

  • Technology Stack:
    The API is developed with .NET 9.0, utilizes Docker for containerization, and is tested with xUnit and TestContainers to ensure reliable, isolated test environments. Stress tests are carried out using NBomber.
  • Exposed Endpoint:
    The API exposes a single GET endpoint:
    http://localhost:8080/best-stories/{storyNumber}
    
  • Scalar Endpoint:
    Although the project does not include a Swagger UI, it provides a Scalar endpoint for quick status checks and diagnostics:
    http://localhost:8080/scalar/
    
  • Distributed Caching:
    The API leverages Redis for distributed caching, improving performance by reducing the number of external calls to the Hacker News API.

Run the application

  1. Clone https://github.com/rustamhajiyev/best-stories.git
  2. Move to the solution directory and restore dependencies
    dotnet restore
    
  3. Start the application suite
    docker-compose up -d
    
  4. Application should be up and running at http://localhost:8080
  5. Test GET /api/BestStories/{n} by inputting value for n, also the GET method can be tested using http://localhost:8080/best-stories/5 as well
  6. Unit test project can be run
    cd HackerNews.API.IntegrationTests/
    dotnet test
    
  7. Stress test project can be run (while the app is running)
    cd HackerNews.API.StressTests/
    dotnet run
    
  8. Stop the application suite
    docker-compose down
    

Assumptions

Slowness in fetching the best stories is well understood as every new request (with different parameter) requires retrieval of all best stories from Hacker News API and getting story details for each story are bit of time-consuming tasks.

Future enhancements

  1. Improve caching mechanism for faster API response time
  2. Improve exception handling
  3. Extend IntegrationTests with more cases
  4. Add support for HTTPS

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published