DeepfakeHTTP – Your 100% static dynamic backend
Features
- No dependencies
- No installation
- No configuration files
- Single-file executable
Command Line Interface (CLI)
java -jar df.jar [options] [dump1.txt] [dump2.txt] ...
Options:
--help print help message
--info print dump files statistics as JSON
--requests print dump requests as JSON
--port TCP port number, default: 8080
--collect <file> append live request/response dumps to file
--no-log disable request/response console logging
--no-etag disable ETag optimization
--no-watch disable watch dump files for changes
Prerequisites
- Java 15 or above
Get started
- Download the latest release of
df.jar
- Copy-paste the content of the dump example to the file
dump-sample.txt
:GET /api/customer/123 HTTP/1.1 HTTP/1.1 200 OK Content-Type: application/json { "id": 123, "fname": "John", "lname": "Doe", "email": ["[email protected]", "[email protected]"] }
- Start the server from command line:
java -jar df.jar dump-sample.txt
- Use a browser to check whether the server is running: http://localhost:8080/api/customer/123
How does it work?
- 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.
Supports
- asynchronous requests and responses
- scriptable response body
- all HTTP methods
- multi-line and multi-value headers
- 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
- watching dump files for changes
- ETag optimization
The DeepfakeHTTP is released under the LicenseMIT license.
Optional response headers
APPENDIX A. 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:
|
X-Request-Delay |
Request delay (in milliseconds). Example:
|
X-Response-Delay |
Response delay (in milliseconds). Example:
|
Dump examples
APPENDIX B. Example 1.
# 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>
Example 2.
#
# 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"
}
Example 3.
#
# 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>
Example 4.
#
# 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>