DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Install / Use
/learn @xnbox/DeepfakeHTTPREADME
<a title="License MIT" href="https://github.com/xnbox/DeepfakeHTTP/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square"></a> <a title="Latest release" href="https://github.com/xnbox/DeepfakeHTTP/releases"><img src="https://img.shields.io/github/v/release/xnbox/DeepfakeHTTP?style=flat-square&color=28A745"></a> <a title="Powered by Tommy" href="https://github.com/xnbox/tommy"><img src="https://img.shields.io/badge/powered_by-Tommy-blueviolet?style=flat-square"></a> <br>
<p id="banner" align="center"> <br> <a href="#banner"><img width="98%" src="https://raw.githubusercontent.com/xnbox/DeepfakeHTTP/main/img/text.png" alt="YOUR 100% STATIC DYNAMIC BACKEND"></a> <table> <tr> <td> <a href="#banner"><img align="left" src="https://raw.githubusercontent.com/xnbox/DeepfakeHTTP/main/img/image1.png" width="190"></a> <h3>What are people using it for?</h3> <ul> <li>Creating the product PoC or demo before even starting out with the backend</li> <li>REST, GraphQL, and other APIs mocking and testing</li> <li>Hiding critical enterprise infrastructure behind a simple static facade</li> <li>Hacking and fine-tuning HTTP communications on both server and client sides</li> </ul> <img width="1000" height="0"> </td> </tr> </table> </p> <p align="center"> <a href="#get-started">Get started</a> | <a href="#usage">Usage</a> | <a href="#usage-examples">Usage Examples</a> | <a href="#how-does-it-work">How does it work?</a> | <a href="#features">Features</a> | <a href="#appendix-boptional-request--response-headers">Optional Headers</a> | <a href="#appendix-acommand-line-options">CLI</a> | <a href="Cheatsheet.md">Cheatsheet</a> </p> <h2>Get started</h2> <ol> <li>Download the <a href="https://github.com/xnbox/DeepfakeHTTP/releases/latest">latest release</a> of <code>df.jar</code></li> <li>Copy-paste the content of the dump example to the file <code>dump.txt</code>: <span></span>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"]
}
</li>
<li>Start the server from command line:
java -jar df.jar --dump dump.txt
</li>
<li>Use a browser to check whether the server is running:
<br>
<pre><a href="http://localhost:8080/api/customer/123">http://localhost:8080/api/customer/123</a></pre>
</li>
<li>Get response:<br>
<a href="#get-started"><img src="https://raw.githubusercontent.com/xnbox/DeepfakeHTTP/main/img/get-started.png"></a>
</li>
</ol>
That's it!
<br><br>
For more examples see the <a href="Cheatsheet.md">cheatsheet</a>.<br>
Also take look at <a href="https://github.com/xnbox/DeepfakeHTTP/tree/main/PetClinic/README#readme">REST version of the Spring PetClinic built with DeepfakeHTTP</a>.
<h2>Usage</h2>
java -jar df.jar [OPTIONS] [FLAGS] [COMMANDS]
OPTIONS:
--host <host> host name, default: localhost
--port <number> HTTP TCP port number, default: 8080
--port-ssl <number> HTTPS TCP port number, default: 8443
--dump <file|url>... dump text file(s)/URL(s)
--db <file|url> json/yaml/csv memory file to populate templates
--db-export <file> export memory to json file
--db-path <path> serve live memory file at specified context
--dir <dir> forward unmatched requests to specified directory
--js <file|url>... JavaScript file(s) for script engine context
--openapi-path <path> serve built-in OpenAPI client at specified context
--openapi-title <text> provide custom OpenAPI specification title
--collect <file> collect live request/response to file
--format <json|yaml> output format for --print-* commands, default: json
--status <number> status code for non-matching requests, default: 404
--max-log-body <number> max body bytes in console log, default: unlimited
FLAGS:
--no-log disable request/response console logging
--no-log-request-info disable request info in console logging
--no-log-headers disable request/response headers in console logging
--no-log-body disable request/response body in console logging
--no-cors disable CORS headers
--no-etag disable 'ETag' header
--no-server disable 'Server' header
--no-watch disable watch files for changes
--no-color disable ANSI color output for --print-* commands
--no-pretty disable prettyprint for --print-* commands
--no-template disable template processing
--no-wildcard disable wildcard processing
--no-bak disable backup old memory file before overwrite
--strict-json enable strict JSON comparison
--redirect enable redirect HTTP to HTTPS
--db-export-on-exit export memory only on server close event
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
<h2>Usage Examples</h2>
Start server on dump file:
<pre>
java -jar df.jar --dump dump.txt
</pre>
Start server with built-in OpenAPI client:
<pre>java -jar df.jar --openapi-path /api --dump dump.txt
</pre>
<details>
<summary>
more examples…
</summary>
<br>
Start server on few dump files:
<pre>
java -jar df.jar --dump dump1.txt dump2.txt dump3.txt
</pre>
Start server with built-in OpenAPI client with custom title:
<pre>
java -jar df.jar --openapi-path /api --openapi-title 'My REST API v18.2.1' --dump dump.txt
</pre>
</details>
<details>
<summary>
even more examples…
</summary>
<br>
Collect live request/response to file:
<pre>
java -jar df.jar --collect /home/john/live.txt --dump dump.txt
</pre>
Specify JSON data file to populate templates:
<pre>
java -jar df.jar --data /home/john/data.json --dump dump.txt
</pre>
Print dump files statistics to stdout as JSON:
<pre>
java -jar df.jar --print-info --dump dump.txt
</pre>
Print dump requests to stdout as JSON:
<pre>
java -jar df.jar --print-requests --dump dump.txt
</pre>
Print OpenAPI specification to stdout as JSON:
<pre>
java -jar df.jar --print-openapi --dump dump.txt
</pre>
</details>
If you still need examples make sure to check out the <a href="Cheatsheet.md">cheatsheet</a>.
<h2>Prerequisites</h2>
<ul>
<li>Java 15 or above</li>
</ul>
<h2>How does it work?</h2>
<ol>
<li>Got the client's request.</li>
<li>Search the dump for corresponded entry (request-response pair) by matching all specified request's parts:<br>
<i>method</i>, <i>URI</i>, <i>headers</i>, and <i>body</i>.</li>
<li>If the entry was found, the server sends the appropriate response to the client.</li>
<li>If the entry was not found, the server sends a status <code>404</code>.</li>
</ol>
That's all.
<h2>Features</h2>
✓ no dependencies<br> ✓ no installation<br> ✓ no configs<br> ✓ crossplatform<br> ✓ single-file executable<br> ✓ command-line interface<br>
<details> <summary> more features… </summary> <br> ✓ fully asynchronous<br> ✓ HTTP message formats RFC 7230<br> ✓ multiple entries per dump<br> ✓ multiple request/response entries per dump<br> ✓ extracts responses from HTTP dumps<br> ✓ self-hosted built-in OpenAPI client<br> ✓ exportable persistent memory<br> ✓ persistent data<br> ✓ CGI, XGI and JavaScript handlers<br> ✓ <code>GET</code>, <code>HEAD</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code> etc.<br> ✓ multi-line and multi-value headers RFC 7230<br> ✓ openAPI-styled templates in paths<br> ✓ wildcards ( <code> *</code> and <code> ?</code> with escape <code> /</code> ) in query string and header values<br> ✓ templates in URI, headers, body<br>  