curl -X POST "https://localhost:7000/api/har/upload" \
-F "[email protected]" \
-F "environmentName=My Test Environment"Response:
{
"environmentId": "a1b2c3d4",
"message": "HAR file uploaded successfully",
"mockUrl": "https://localhost:7000/mock/a1b2c3d4"
}curl -X GET "https://localhost:7000/api/har/environments"If your HAR contained a request to GET https://api.example.com/users/123, you can now call:
curl -X GET "https://localhost:7000/mock/a1b2c3d4/users/123"curl -X GET "https://localhost:7000/api/har/environments/a1b2c3d4"- Environment Isolation: Each HAR file creates a separate environment with its own mock responses
- Domain Replacement: Original domains are replaced with the local mock server while preserving paths
- Fast Lookup: In-memory dictionary for O(1) response lookup by method+path
- YARP Integration: Uses YARP's IHttpForwarder for efficient request handling
- Flexible Matching: Supports exact path matching and fallback to path-only (ignoring query params)
- Production Ready: Comprehensive logging, error handling, and scalable architecture
- RESTful API: Full CRUD operations for managing HAR environments
- Create a new .NET 8 Web API project
- Replace the default files with the code above
- Run:
dotnet run - Access Swagger UI at:
https://localhost:7000/swagger - Upload HAR files via the API and start mocking!
This solution provides a complete, scalable HAR mock server that leverages YARP for efficient request processing and serves immediate mock responses for your testing needs.