http-server-sim
1.1.0.402-beta
See the version list below for details.
dotnet tool install --global http-server-sim --version 1.1.0.402-beta
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local http-server-sim --version 1.1.0.402-beta
#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
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:
- Create a rule file defining the endpoints and their behaviors.
- Place the rule file in the appropriate directory.
- 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
- Method Conditions: These specify the HTTP method (e.g.,
GET
,POST
) that the request must match. - URL Path Conditions: These specify the URL path that the request must match.
The supported operators are: Equals
, StartWith
, and Contains
Product | Versions 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. 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. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
1.3.0.526-beta | 65 | 1/17/2025 |
1.3.0.523-beta | 198 | 10/16/2024 |
1.3.0.513-beta | 81 | 10/15/2024 |
1.3.0.489-beta | 80 | 9/12/2024 |
1.2.0.471 | 127 | 8/27/2024 |
1.1.0.464 | 135 | 8/14/2024 |
1.1.0.435 | 110 | 8/7/2024 |
1.1.0.429 | 107 | 8/6/2024 |
1.1.0.421 | 93 | 8/3/2024 |
1.1.0.420-beta | 77 | 8/3/2024 |
1.1.0.410 | 81 | 7/30/2024 |
1.1.0.402-beta | 91 | 7/25/2024 |
1.1.0.394 | 95 | 7/23/2024 |
1.1.0.390-beta | 80 | 7/22/2024 |