This README provides the steps to set up and run the Story.API
project with Redis using Docker Compose. The application implements a RESTful API to retrieve the first n
"best stories" from the Hacker News API and returns them sorted by score in descending order.
Ensure you have the following installed on your system:
-
Open a terminal and navigate to the solution directory.
-
Run the following command to build and start the services:
docker-compose up --build
This will:
- Build the
Story.API
Docker image. - Start the
Story.API
and Redis containers.
- Build the
- Access the
Story.API
Swagger UI at: http://localhost:5000/swagger (replace5000
with the port configured in yourdocker-compose.override.yml
, if different). - Redis will be running internally and is accessible to
Story.API
.
To stop the containers, press Ctrl+C
in the terminal or run:
docker-compose down
To run the services in the background, add the -d
flag:
docker-compose up --build -d
Open HackerNewsWrapper.sln
in Visual Studio 2022 and run the Docker Compose
profile in Debug mode.
- Client: Consumer of the Story API.
- Story API: .NET 8 Web API project.
- Best Stories Service: Service responsible for retrieving best stories from Hacker News if not available in Redis cache.
- Redis Cache: Caches processed stories, best stories, and content for each story.
- Hacker News API: External API to retrieve data from Hacker News.
- Client requests the top
n
best stories. - Checks for already processed
n
best stories in cache; if found, return processed stories. - If processed stories are not found, proceed with the normal flow. Check for best story IDs in cache. If not found, fetch them from Hacker News API and cache them.
- Retrieve the top
n
stories from the cached best stories. - For each story, check if content is in cache by the key
story_{id}
. If not, fetch the content of each story from Hacker News API and cache it. - Sort stories by score in descending order.
- Cache the processed top
n
stories. - Return the processed stories to the caller.
- Efficient Handling: The application caches responses to reduce calls to the Hacker News API.
- Error Handling: The API gracefully handles invalid
n
values and network errors.
- Pagination Support: Add support for paginated responses.
- Authentication: Implement authentication and authorization mechanisms to secure API endpoints and manage user access.
- Rate Limiting: Introduce rate-limiting middleware for better API control.
- Refactor Service Registration: Add extensions methods for service registriation.
- Cache duration: Add cache duration to appsettings
Lukasz Sil ([email protected])