sameerk.HttpPlaygroundServer 1.0.0

dotnet add package sameerk.HttpPlaygroundServer --version 1.0.0
                    
NuGet\Install-Package sameerk.HttpPlaygroundServer -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="sameerk.HttpPlaygroundServer" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="sameerk.HttpPlaygroundServer" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="sameerk.HttpPlaygroundServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add sameerk.HttpPlaygroundServer --version 1.0.0
                    
#r "nuget: sameerk.HttpPlaygroundServer, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package sameerk.HttpPlaygroundServer@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=sameerk.HttpPlaygroundServer&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=sameerk.HttpPlaygroundServer&version=1.0.0
                    
Install as a Cake Tool

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:

  1. It creates (if needed) a folder structure based on the URL path.
  2. The request is logged into the Requests subfolder with a timestamped JSON file.
  3. The server looks for a mock response file in the Responses subfolder.
  4. If found, the file is used to construct the response.
  5. 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 ServerConfig options
  • How to start the server loop with proper async/await usage
  • How to organize your Requests and Responses folders
  • 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 (or 201 for POST, 204 for 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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