http-server-sim 1.1.0.402-beta

This is a prerelease version of http-server-sim.
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global http-server-sim --version 1.1.0.402-beta                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local http-server-sim --version 1.1.0.402-beta                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=http-server-sim&version=1.1.0.402-beta&prerelease                
nuke :add-package http-server-sim --version 1.1.0.402-beta                

http-server-sim

Build Status

HTTP Server Simulator is a .NET tool that runs a Web API simulating HTTP endpoints, supporting the development and testing of components that use HTTP.

http-server-sim can be called from the shell/command line.

Usage

Installation

Install the latest version from NuGet:

dotnet tool install --global http-server-sim

Once http-server-sim is installed as a global tool, it can be executed from any folder. For other versions and more information, visit NuGet and dotnet tool install.

Rule file

The simulation of endpoints is based on a rule file. Here’s how it can be set up:

  1. Create a rule file defining the endpoints and their behaviors.
  2. Place the rule file in the appropriate directory.
  3. Run the simulator with the rule file.

Example of rule file.

{
  "rules": [
    {
      "name": "customers-post",
      "description": "",
      "conditions": [
        { "field": "Method", "operator": "Equals", "value": "POST" },
        { "field": "Path", "operator": "Contains", "value": "/customers" }
      ],
      "response": {
        "statusCode": 200
      }
    }
  ]
}

Example command (assuming that the file rule.json is in the current folder where the command http-server-sim is being executed):

http-server-sim --Rules rules.json

The following POST request is handled using the rule customers-post:

curl --location 'http://localhost:5000/customers' --header 'Content-Type: application/json' --data '{"id":10,"name":"Juan"}' -v

http-server-sim returns a response with 200.

The following GET request:

curl --location 'http://localhost:5000/customers' -v

returns 404 with content Rule matching request not found

http-server-sim output:

Request:
Accept: */*
Host: localhost:5000
User-Agent: curl/8.7.1
Protocol: HTTP/1.1
Method: GET
Scheme: http
PathBase:
Path: /customers

warn - HttpServerSim.App
Rule matching request not found.

Response:
StatusCode: 404

http-server-sim CLI options

Option Description
--ControlUrl <url> URL for managing rules dynamically. Not required. Example: http://localhost:5001.
--Help Prints the help.
--LogControlRequestAndResponse Whether control requests and responses are logged. Default: false.
--LogRequestAndResponse Whether requests and responses are logged. Default: true.
--Rules <file-name> <path> Rules file. It can be a file name that exists in the current directory or a full path to a file.
--Url <url> URL for simulating endpoints. Default: http://localhost:5000
--Url and --ControlUrl cannot share the same value.

Rule conditions

When http-server-sim processes a request, it uses rule conditions to match a rule to the request.

Example of conditions:

"conditions": [
  { "field": "Method", "operator": "Equals", "value": "POST" },
  { "field": "Path", "operator": "Contains", "value": "/customers" }
]

This condition applies when:

  • The request method is POST, and
  • The URL path contains /customers.

There are two types of conditions, Method and Path

  1. Method Conditions: These specify the HTTP method (e.g., GET, POST) that the request must match.
  2. URL Path Conditions: These specify the URL path that the request must match.

The supported operators are: Equals, StartWith, and Contains

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.2.0.471 60 8/27/2024
1.1.0.464 73 8/14/2024
1.1.0.435 68 8/7/2024
1.1.0.429 66 8/6/2024
1.1.0.421 51 8/3/2024
1.1.0.420-beta 45 8/3/2024
1.1.0.410 42 7/30/2024
1.1.0.402-beta 57 7/25/2024
1.1.0.394 61 7/23/2024
1.1.0.390-beta 53 7/22/2024