sameerk.HttpPlaygroundServer
1.0.0
dotnet add package sameerk.HttpPlaygroundServer --version 1.0.0
NuGet\Install-Package sameerk.HttpPlaygroundServer -Version 1.0.0
<PackageReference Include="sameerk.HttpPlaygroundServer" Version="1.0.0" />
<PackageVersion Include="sameerk.HttpPlaygroundServer" Version="1.0.0" />
<PackageReference Include="sameerk.HttpPlaygroundServer" />
paket add sameerk.HttpPlaygroundServer --version 1.0.0
#r "nuget: sameerk.HttpPlaygroundServer, 1.0.0"
#:package sameerk.HttpPlaygroundServer@1.0.0
#addin nuget:?package=sameerk.HttpPlaygroundServer&version=1.0.0
#tool nuget:?package=sameerk.HttpPlaygroundServer&version=1.0.0
Http Playground Server
A lightweight local HTTP server for testing, debugging, and inspecting HTTP requests. It logs all incoming requests (URL, headers, body) and returns mock responses from predefined files, allowing you to simulate various scenarios without the overhead of running a full web service.
Features
- ๐ Run a lightweight HTTP test server locally
- ๐ Automatically logs request URL, headers, and body
- ๐ Stores each request in a timestamped JSON file
- ๐ Returns mock responses based on files in a Responses folder
- ๐๏ธ Supports query-based response selection (
?respFile=) - ๐งช Simulates various HTTP results for testing and automation
How It Works
When the server receives an HTTP request:
- It creates (if needed) a folder structure based on the URL path.
- The request is logged into the Requests subfolder with a timestamped JSON file.
- The server looks for a mock response file in the Responses subfolder.
- If found, the file is used to construct the response.
- If not found, a default success response is returned.
Example folder layout for d:/temp and request to /Pets/Cats:
d:/temp/Pets/Cats/
Requests/
Responses/
How to Use
1. Create a Console App
2. Install the NuGet Package
sameerk.HttpPlaygroundServer
3. Ensure Main is async
static async Task Main(string[] args)
4. Start the Server
// cancellation token for the server loop
CancellationTokenSource cts = new CancellationTokenSource();
// this is signaled when the server starts
ManualResetEventSlim serverStarted = new();
// Update server storage folder
string storageFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestData");
ServerConfig.StorageFolder = storageFolder;
Console.WriteLine($"Storage Folder is {ServerConfig.StorageFolder}");
// instantiate and run the server
HttpPlaygoundServer httpTestListener = new();
Task httpListener = Task.Run(() => httpTestListener.StartHttpListner(serverStarted, cts.Token));
// wait for server to start
serverStarted.Wait();
Sample Code
Sample code demonstrating how to set up and use the Http Playground Server is available in this repository:
๐ GitHub: https://github.com/sameerkapps/HttpPlayground
The sample project includes:
- How to configure the
ServerConfigoptions - How to start the server loop with proper async/await usage
- How to organize your
RequestsandResponsesfolders - Example mock response files
- A minimal console app you can copy and adapt for your own tests
- A Test app with a wide range of scenarios
This sample is the quickest way to understand the expected folder structure, response file format, and overall workflow.
Request Logging
When a request is received, the server ensures that the folder structure based on the request URI exists or is created.
e.g. GET /Pets/Cats request is saved in:
/Pets/Cats/Requests/GET-20251109-130233.340.json
Request File Format
{
"Uri": "uri of the request",
"Headers": {
"key": "value"
},
"Body": {
// JSON or body received
}
}
Mock Responses
To respond, the server checks for a response file in the Responses folder.
Example for:
GET http://localhost:8080/Pets/Cats
It looks for:
d:/temp/Pets/Cats/Responses/Get.json
If the file is missing, it will return following HttpStatusCode:
- Default:
200 OK(or201for POST,204for DELETE`)
Query-Based Response Selection
If the request contains:
?respFile=GetAll.json
Then the server will look for:
d:/temp/Pets/Cats/Responses/GetAll.json
If respFile is specified and missing โ it will return 404 Not Found
Response File Format
{
"HttpStatusCode": "desired status code",
"Headers": {
"key": "value"
},
"Body": {
// JSON or text
}
}
Configuration
Default values exist for the port, hostname, and storage folder.
You can override them by setting values on the ServerConfig object:
ServerConfig.Port = 8080;
ServerConfig.HostName = "localhost";
ServerConfig.StorageFolder = "d:/temp";
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- System.Text.Json (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 212 | 11/23/2025 |
Initial release