Sitelet https://github.com/xnbox/DeepfakeHTTP/tree/v4.1.1
Skip to content

Repository files navigation

DeepfakeHTTP
Your 100% static dynamic backend

Get started | Usage | Usage Examples | How does it work? | Features | Optional Headers | Cheatsheet

What are people using it for?

  • Creating the product PoC or demo before even starting out with the backend
  • REST, GraphQL, and other APIs mocking and testing
  • Hiding critical enterprise infrastructure behind a simple static facade
  • Hacking and fine-tuning HTTP communications on both server and client sides

Get started

  1. Download the latest release of df.jar
  2. 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"]
    }
  3. Start the server from command line:
    java -jar df.jar --dump dump.txt
    
  4. Use a browser to check whether the server is running:
    http://localhost:8080/api/customer/123

  5. Get response:
That's it!

For more examples, see the cheatsheet.

Usage

java -jar df.jar [OPTIONS] [FLAGS] [COMMANDS]

OPTIONS:                                                                      
   --port <number>         HTTP TCP port number, default: 8080                
   --port-ssl <number>     HTTPS TCP port number, default: 8443               
   --dump <file|url>...    dump text file(s) and/or OpenAPI json/yaml file(s) 
   --data <file|url>...    json/yaml/csv data file(s) to populate templates   
   --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              
   --format <json|yaml>    output format for --print-* commands, default: json
   --status <number>       status code for non-matching requests, default: 400
   --max-log-body <number> max body bytes in console log, default: unlimited  
                                                                              
FLAGS:                                                                        
   --no-log                disable request/response 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-powered-by         disable 'X-Powered-By' 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                        
   --strict-json           enable strict JSON comparison                      
   --redirect              enable 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 

Usage Exampes

Start server on dump file:
java -jar df.jar --dump dump.txt
Start server on OpenAPI file:
java -jar df.jar --dump openapi.json
Start server with built-in OpenAPI client:
java -jar df.jar --openapi-path /api --dump dump.txt
more examples…
Start server on few dump files:
java -jar df.jar --dump dump1.txt dump2.txt dump3.txt
Start server on mix of dump and OpenAPI files:
java -jar df.jar --dump dump1.txt openapi2.json dump3.txt openapi4.yaml
Start server with built-in OpenAPI client with custom title:
java -jar df.jar --openapi-path /api --openapi-title 'My Killer REST API v18.2.1' --dump dump.txt
even more examples…
Collect live request/response to file:
java -jar df.jar --collect /home/john/live.txt --dump dump.txt
Specify JSON data file to populate templates:
java -jar df.jar --data /home/john/data.json --dump dump.txt
Print dump files statistics to stdout as JSON:
java -jar df.jar --print-info --dump dump.txt
Print dump requests to stdout as JSON:
java -jar df.jar --print-requests --dump dump.txt
Print OpenAPI specification to stdout as JSON:
java -jar df.jar --print-openapi --dump dump.txt

Prerequisites

  • Java 15 or above

How does it work?

  1. Got the client's request.
  2. Search the dump for corresponded entry (request-response pair) by matching all specified request's parts:
    method, URI, headers, and body.
  3. If the entry was found, the server sends the appropriate response to the client.
  4. If the entry was not found, the server sends a status 400 (400 Bad request).
That's all.

Features

  • No dependencies, no installation, no configs
  • Crossplatform single-file executable
  • Retrieve response data from HTTP dumps and/or OpenAPI JSON/YAML
more features…
  • Optional built-in OpenAPI client
  • Asynchronous requests and responses
  • HTTP message formats (RFC 7230)
  • Unlimited number of request/response pairs in the dump
  • Supports methods: 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 URI, headers, body
  • JSON/YAML/CSV data files to populate templates
  • 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 support
  • Optional CORS support
  • 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
  • Colorized console output
  • Disabling color via NO_COLOR environment variable

LICENSE

The DeepfakeHTTP is released under the MIT license.



APPENDIX A.
Optional request headers

HeaderDescription
X-Delay

Request delay (in milliseconds).

Example:
# Two seconds request delay.

HTTP/1.1 200 OK
X-Delay: 2000

{"id": 5, "name": "John Doe"}
X-OpenAPI-Summary

OpenAPI request summary text.

Example:
HTTP/1.1 200 OK
Content-Type: application/json
X-OpenAPI-Summary: Get customer information

{"id": 5, "name": "John Doe"}
X-OpenAPI-Description

OpenAPI request description text.

Example:
HTTP/1.1 200 OK
Content-Type: application/json
X-OpenAPI-Summary: Get customer information
X-OpenAPI-Description: This API extracts customer info from db

{"id": 5, "name": "John Doe"}
X-OpenAPI-Tags

OpenAPI request comma-separated tag list.

Example:
HTTP/1.1 200 OK
Content-Type: application/json
X-OpenAPI-Summary: Get customer information
X-OpenAPI-Description: This API extracts customer info from db
X-OpenAPI-Tags: Work with customer, Buyers, Login info

{"id": 5, "name": "John Doe"}
NOTE: Optional request headers will not be sent to the server engine.

APPENDIX B.
Optional response headers

HeaderDescription
X-Delay

Response delay (in milliseconds).

Example:
# Two seconds response delay.

HTTP/1.1 200 OK
X-Delay: 2000

{"id": 5, "name": "John Doe"}
X-Content-Source

The URL of the externally hosted content. The content from the URL will be sent as the response body. Supported protocols: http:, https:, file:, data:.
If the URL provides its own content type and there is no Content-Type header in the dump, the original Content-Type header received from the URL will be sent along with other response headers.

This header is useful when you want to send content hosted on a remote server or just send binary data as a response body.

Examples:

Get a response body from a remote server.

HTTP/1.1 200 OK
Content-Type: application/json
X-Content-Source: http://example.com/api/car/1234.json

Get a response body from a file.

HTTP/1.1 200 OK
Content-Type: image/jpeg
X-Content-Source: file:///home/john/photo.jpeg

Get a response body from a data URI.

HTTP/1.1 200 OK
Content-Type: image/gif
X-Content-Source: data:image/gif;base64,R0lGODlhAQABAIAAAP...
X-CGI

CGI (Common Gateway Interface) program.

Example:
HTTP/1.1 000
X-CGI: /home/john/myprog.sh param1 param2
NOTE: Optional response headers will not be sent to clients.

About

DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.

Topics

Resources

Stars

526 stars

Watchers

9 watching

Forks

Releases

Contributors

Languages