- Download the latest release of
df.jar
- Copy-paste the content of the dump example to the file
dump.txt
:GET /api/customer/123 HTTP/1.1 HTTP/1.1 200 OK Content-Type: application/json { "id": 123, "fname": "John", "lname": "Doe", "email": ["john@example.com", "johndoe@example.com"] }
- Start the server from command line:
java -jar df.jar dump.txt
- Use a browser to check whether the server is running: http://localhost:8080/api/customer/123
java -jar df.jar [OPTIONS] [FLAGS] [COMMANDS] <file>...
OPTIONS:
--port <number> HTTP TCP port number, default: 8080
--port-ssl <number> HTTPS TCP port number, default: 8443
--openapi-path <path> serve OpenAPI client at specified context path
--openapi-title <text> provide custom OpenAPI spec title
--collect <file> collect live request/response to file
--data <file> specify json/yaml data file to populate templates
--format <json|yaml> output format for --print-* commands, default: json
FLAGS:
--no-log disable request/response console logging
--no-etag disable ETag optimization
--no-watch disable watch files for changes
--no-pretty disable prettyprint for --print-* commands
--redirect redirect HTTP to HTTPS
COMMANDS:
--help print help message
--print-info print dump files statistics to stdout as json/yaml
--print-requests print dump requests to stdout as json/yaml
--print-openapi print OpenAPI specification to stdout as json/yaml
️ARGS:
<file>... dump text file(s) and/or OpenAPI json/yaml file(s)
java -jar df.jar dump.txtStart server on OpenAPI file:
java -jar df.jar openapi.jsonStart server with built-in OpenAPI client:
java -jar df.jar --openapi-path /api dump.txt
more examples…
Start server on few dump files:
java -jar df.jar dump1.txt dump2.txt dump3.txtStart server on mix of dump and OpenAPI files:
java -jar df.jar dump1.txt openapi2.json dump3.txt openapi4.yamlProvide custom OpenAPI spec title:
java -jar df.jar --openapi-path /api --openapi-title 'My Killer REST API v18.2.1' dump.txt
- Java 15 or above
- Got client request
- Search dump entries (request-response pairs) for appropriate entry by matching all specified request parts:
method, URI, headers, and body - If entry is found, the server generates a corresponded response and sends it to the client
- If entry is not found, the server search dump entries for response with status
400
(Bad request). - If entry is found, the server send entry to the client
- If entry is not found, the server sends status
400
with no body.
- No dependencies
- No installation
- No configuration files
- Single-file executable
- Built-in OpenAPI client
- Asynchronous requests and responses.
- HTTP message formats (RFC 7230)
- Unlimited number of request/response pairs in the dump
- Scriptable response body
GET
,HEAD
,POST
,PUT
,DELETE
etc.- Multi-line and multi-value headers (RFC 7230).
- OpenAPI-styled templates in paths.
- Wildcards (
*
and?
with escape/
) in query string and header values. - Templates in response body
- Response body fetching from external sources like URLs, local files, and data URI
- Per entry user-defined request and response delays
- Comments
#
in dumps - Live request/response collection
- Optional watching dump files for changes
- Optional ETag optimization
- Optional live request/response logging
- TLS(SSL) connections and HTTP to HTTPS redirect
- Customizable OpenAPI client path
- Latest OpenAPI specification (v3.0.3) in JSON and YAML format
Header | Description |
---|---|
X-OpenAPI-Summary |
OpenAPI request summary text. Example:
|
X-OpenAPI-Description |
OpenAPI request description text. Example:
|
X-OpenAPI-Tags |
OpenAPI request comma-separated tag list. Example:
|
Header | Description |
---|---|
X-Body-Type |
Tells the server what the content type (media type) of the body content actually is. Value of this header has same rules as value of standard HTTP This header is useful when you want to use binary data, template or script as a response body. Examples:A response body is a character data (default).
Get a response body from a remote server.
Get a response body from a file.
Get a response body from a data URI.
Get a response body from a template.
|
X-Request-Delay |
Request delay (in milliseconds). Example:
|
X-Response-Delay |
Response delay (in milliseconds). Example:
|
# Comments are welcome! :)
# Please don't miss a single carriage return between headers and body!
GET /form.html HTTP/1.1
.
# Fake HTML file :)
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/add_user.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
.
POST /add_user.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
.
# Fake PHP file :)
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
#
# First request-response entry
#
# Client request
GET /api/customer/5 HTTP/1.1
Accept-Language: ru;*
.
# Server response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "Джон Доу"
}
.
#
# Second request-response entry
#
# Client request
GET /api/customer/5 HTTP/1.1
.
# Server response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "John Doe"
}
#
# Work with HTML forms (1)
#
GET /form.html HTTP/1.1
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/action_page.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /action_page.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
#
# Work with HTML forms (2)
#
GET /form.html HTTP/1.1
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/action_page.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<p>Only first name 'John' and last name 'Doe' are supported.<br>
Expected output is: Hello, John Doe!,<br>
or HTTP status 400 Bad request if first name is not 'John' or last name is not 'Doe'.
</p><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /action_page.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
fname=John&lname=Doe
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>