Welcome to DeepfakeHTTP Cheatsheet!
Table of Contents
Hello, World!
-
Prepare 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 server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/api/customer/123
-
Get response:
{
"id": 123,
"fname": "John",
"lname": "Doe",
"email": ["john@example.com", "johndoe@example.com"]
}
⚡️ Hacks and Tips:
- DeepfakeHTTP also supports
HEAD, POST, PUT, DELETE etc. methods
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
# Client request
GET /api/customer/123 HTTP/1.1
.
# Server response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 123,
"fname": "John",
"lname": "Doe",
"email": ["john@example.com", "johndoe@example.com"]
}
.
# Some comments at the end (ater "." character)
# More comments...
⚡️ Hacks and Tips:
- Comments are not part of output.
- Comment your dums with
# character.
- Only single lines comments are supported.
- If you need comment after the body, use period (full stop) character
. to mark end of body.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
-
Prepare file
dump.txt:
GET /form1.html HTTP/1.1
.
# Fake HTML file :)
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
.
# Fake PHP response :)
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE html>
<html lang="en">
<body>
Hello ${request.parameters.fname[0]} ${request.parameters.lname[0]}!
</body>
</html>
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/form1.html
-
Fill in input fields. Eg.: John Doe
-
Get response:
Hello John Doe!
⚡️ Hacks and Tips:
- DeepfakeHTTP supports
GET, HEAD, POST, PUT, DELETE etc. methods
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
-
Prepare file
dump.txt:
GET /form2.html HTTP/1.1
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/action_page2.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname" value="John"><br>
<br>
<label for="lname">Last name: </label><input type="text" name="lname" value="Doe"><br>
<p>
Only the first name <i>John</i> and the last name <i>Doe</i> are supported.
<br>
Expected result is: <strong>Hello John Doe!</strong>,<br>
or HTTP status <strong><code>404 Not found</code></strong><br>
when first name is not <i>John</i> or last name is not <i>Doe</i>.
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /action_page2.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
fname=John&lname=Doe
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE html>
<body>
Hello ${request.parameters.fname[0]} ${request.parameters.lname[0]}!
</body>
</html>
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/form2.html
-
Fill in input fields. Eg.: John Doe
-
Expected response:
Hello John Doe!
-
Fill in input fields. Eg.: Lora Corban
-
Expected result:
Request failed with status: 404 Not found
⚡️ Hacks and Tips:
- DeepfakeHTTP supports
GET, HEAD, POST, PUT, DELETE etc. methods
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
-
Prepare file
dump.txt:
GET /api/customer/5 HTTP/1.1
Accept-Language: ru;*
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "Джон Доу"
}
GET /api/customer/5 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "John Doe"
}
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/api/customer/5
-
Expected result:
{
"id": 5,
"name": "John Doe"
}
- Change browser's preferred language to Russian
-
Navigate to:
http://localhost:8080/api/customer/5
-
Expected result:
{
"id": 5,
"name": "Джон Доу"
}
⚡️ Hacks and Tips:
- If headers was provided in the request, they will be included in match algorithm
- If body was provided in the request, it will be included in match algorithm
- DeepfakeHTTP supports wildcards (
* and ?) in request query string and headers
- Esacape character for wildcards is
/
- DeepfakeHTTP supports OpenAPI-styled parameters in path
- DeepfakeHTTP supports templates in request line, headers and body
💡 See Also:
|
Request parameters in template
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile?mode=* HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "${request.parameters.id[0]}",
"mode": "${request.parameters.mode[0]}",
"fname": "John",
"lname": "Doe"
}
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/api/customers/123/profile?mode=open
-
Get response:
{
"id": "123",
"mode": "open",
"fname": "John",
"lname": "Doe"
}
⚡️ Hacks and Tips:
- Parameters are always treated as strings.
- Multivalued query parameters:
?mode=open&mode=tmp ➞ ${request.parameters.mode[1]} ➞ tmp.
- Multivalued path parameters:
/{id}/car/{id} ➞ /123/car/tesla ➞ ${request.parameters.id[1]} ➞ tesla.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
Multivalued request parameters
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile/{id}/info?mode=open&mode=* HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id1": "${request.parameters.id[0]}",
"id2": "${request.parameters.id[1]}",
"mode1": "${request.parameters.mode[0]}",
"mode2": "${request.parameters.mode[1]}",
"name": "John Doe"
}
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/api/customers/123/profile/abc/info?mode=open&mode=tmp
-
Get response:
{
"id1": "123",
"id2": "abc",
"mode1": "open",
"mode2": "tmp",
"name": "John Doe"
}
⚡️ Hacks and Tips:
- Parameters are always treated as strings.
- Query parameters can contain wildcards
*, ?: ?mode=*&virus=covid-?? ➞ ?mode=open&virus=covid-19.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
OpenAPI-styled parameters in path
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "${request.parameters.id[0]}",
"fname": "John",
"lname": "Doe"
}
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/api/customers/123/profile
-
Get response:
{
"id": "123",
"fname": "John",
"lname": "Doe"
}
⚡️ Hacks and Tips:
- Parameters are always treated as strings.
- Multivalued path parameters:
/{id}/car/{id} ➞ /123/car/tesla ➞ ${request.parameters.id[1]} ➞ tesla.
- Query parameters also supported:
?mode=open ➞ ${request.parameters.mode[0]} ➞ open.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
External data and request parameters in template
-
Prepare external data file
customers.json:
[
{"fname": "John", "lname": "Doe", "email": ["john@example.com", "johndoe@example.com"]},
{"fname": "Lora", "lname": "Corban", "email": ["lora@example.com", "loracorban@example.com"]},
{"fname": "Ted", "lname": "Brown", "email": ["tedbrown@example.com"]}
]
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile?mode=* HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "${request.parameters.id[0]}",
"mode": "${request.parameters.mode[0]}",
"fname": "${data.customers[1].fname}",
"lname": "${data.customers[1].lname}"
}
-
Start server:
java -jar df.jar --dump dump.txt --db customers.json
-
Navigate to:
http://localhost:8080/api/customers/123/profile?mode=open
-
Get response:
{
"id": "123",
"mode": "open",
"fname": "Lora",
"lname": "Corban"
}
⚡️ Hacks and Tips:
- Parameters are always treated as strings.
- The data file can be organized as an object or an array.
- You can select a random record from the data file.
- DeepfakeHTTP supports JSON, YAML and CSV data files.
- By default, data files are watched for changes. Use
--no-watch option to disable watching.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
Random data in template
-
Prepare external data file
customers.json:
[
{"fname": "John", "lname": "Doe", "email": ["john@example.com", "johndoe@example.com"]},
{"fname": "Lora", "lname": "Corban", "email": ["lora@example.com", "loracorban@example.com"]},
{"fname": "Ted", "lname": "Brown", "email": ["tedbrown@example.com"]}
]
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "${request.parameters.id[0]}",
"name": "${random(data.customers).fname + ' ' + random(data.customers).lname}"
}
-
Start server:
java -jar df.jar --dump dump.txt --db customers.json
-
Navigate to:
http://localhost:8080/api/customers/123/profile
-
Get response:
{
"id": "123",
"name": "Ted Brown"
}
⚡️ Hacks and Tips:
- The data file can be organized as an object or an array.
- You can select record from the data file by index.
- DeepfakeHTTP supports JSON, YAML and CSV data files.
- By default, data files are watched for changes. Use
--no-watch option to disable watching.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
Provide favicon as binary data
-
Prepare file
dump.txt:
GET /favicon.ico HTTP/1.1
HTTP/1.1 200 OK
X-Content-Source: data:image/vnd.microsoft.icon;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAA
AAIAAAAAEAGAAAAAAAAAMAABILAAASCwAAAAAAAAAAAAASVuwSVuwSVuwSVuwAif8Aif8Aif8A
if8Aif8Aif8Aif8Aif8SVuwSVuwSVuwSVuwSVuwSVuwAif8Aif8Aif8Aif8Aif8Aif8Aif8Aif
8Aif8Aif8Aif8Aif8SVuwSVuwSVuwAif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8A
if8Aif8Aif8SVuwSVuwAif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif
8SVuwAif8Aif8Aif8Aif8Aif8AAwYAAwYAAwYAAwYAAwYAAwYAif8Aif8Aif8Aif8Aif8Aif8A
if8Aif8Aif8AAwYAAwYAif8Aif8Aif8Aif8AAwYAAwYAif8Aif8Aif8Aif8Aif8Aif8Aif8Aif
8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8A
if8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif
8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8A
if8Aif8Aif8Aif8Aif8Aif8Aif8AAwYAif8AAwYAAwYAif8Aif8Aif8AAwYAAwYAif8Aif8AAw
YAif8Aif8Aif8Aif8Aif8AAwYAAwYAif8Aif8Aif8Aif8Aif8AAwYAAwYAAwYAif8Aif8Aif8S
VuwAif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8SVuwSVuwAif8Aif
8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8SVuwSVuwSVuwAif8Aif8Aif8A
if8Aif8Aif8Aif8Aif8Aif8Aif8Aif8Aif8SVuwSVuwSVuwSVuwSVuwSVuwAif8Aif8Aif8Aif
8Aif8Aif8Aif8Aif8SVuwSVuwSVuwSVuzwDwAAwAMAAIABAACAAQAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAACAAQAAgAEAAMADAADwDwAA
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080
-
Get response:
The favicon is displayed next to the title of the web page in the browser tab.
⚡️ Hacks and Tips:
- Serve any media type by using
X-Content-Source response header.
- With
X-Content-Source response header you can use also http://, https://, file://, and data:// URLs.
- Don't miss a single carriage return between headers and body!
💡 See Also:
|
Response with binary data
-
Prepare file
dump.txt:
GET /Albert_Einstein.jpeg HTTP/1.1
HTTP/1.1 200 OK
Content-Type: image/jpeg
X-Content-Source: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAMCAgICAgMCAgIDAwMDB
AYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDA
wQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
BAQEBD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kGtnhkyVyuXCt8h1FEfETGbq3hfVDdychWLF
StP5R8hx1FQ5DBu7PzB6OOMKh0xNLpFtQO/m4lxoBNDfPTGFGikeGf/2Q==
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/Albert_Einstein.jpeg
-
Get response:
⚡️ Hacks and Tips:
- Serve any media type by using
X-Content-Source response header.
- With
X-Content-Source response header you can use also http://, https://, file://, and data:// URLs.
💡 See Also:
|
Generate PDF document and populate it with request parameters
-
Prepare file
dump.txt:
GET /customers/{id}/purchases/{date}/report?format=pdf HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/pdf
%PDF-1.3
1 0 obj
<<
/Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
<<
/Type /Outlines
/Count 0
>>
endobj
3 0 obj
<<
/Type /Pages
/Count 2
/Kids [ 4 0 R 6 0 R ]
>>
endobj
4 0 obj
<<
/Type /Page
/Parent 3 0 R
/Resources <<
/Font <<
/F1 9 0 R
>>
/ProcSet 8 0 R
>>
/MediaBox [0 0 612.0000 792.0000]
/Contents 5 0 R
>>
endobj
5 0 obj
<< /Length 1074 >>
stream
2 J
BT
0 0 0 rg
/F1 0027 Tf
57.3750 722.2800 Td
( Customer ID: ${request.parameters.id[0]}) Tj
ET
BT
/F1 0010 Tf
69.2500 688.6080 Td
( Date: ${request.parameters.date[0]} ) Tj
ET
BT
/F1 0010 Tf
69.2500 664.7040 Td
( Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore ) Tj
ET
BT
/F1 0010 Tf
69.2500 652.7520 Td
( et dolore magna aliq ua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi. ) Tj
ET
endstream
endobj
6 0 obj
<<
/Type /Page
/Parent 3 0 R
/Resources <<
/Font <<
/F1 9 0 R
>>
/ProcSet 8 0 R
>>
/MediaBox [0 0 612.0000 792.0000]
/Contents 7 0 R
>>
endobj
7 0 obj
<< /Length 676 >>
stream
2 J
BT
0 0 0 rg
/F1 0027 Tf
57.3750 722.2800 Td
( Customer ID: ${request.parameters.id[0]}) Tj
ET
BT
/F1 0010 Tf
69.2500 688.6080 Td
( Date: ${request.parameters.date[0]} ) Tj
ET
BT
/F1 0010 Tf
69.2500 664.7040 Td
( More text... ) Tj
ET
endstream
endobj
8 0 obj
[/PDF /Text]
endobj
9 0 obj
<<
/Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
/Encoding /WinAnsiEncoding
>>
endobj
10 0 obj
<<
/Creator (DeepfakeHTTP \(https://github.com/xnbox/DeepfakeHTTP))
/Producer (DeepfakeHTTP)
/CreationDate (D:20210925043107)
>>
endobj
xref
0 11
0000000000 65535 f
0000000019 00000 n
0000000093 00000 n
0000000147 00000 n
0000000222 00000 n
0000000390 00000 n
0000001522 00000 n
0000001690 00000 n
0000002423 00000 n
0000002456 00000 n
0000002574 00000 n
trailer
<<
/Size 11
/Root 1 0 R
/Info 10 0 R
>>
startxref
2714
%%EOF
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/customers/123456/purchases/2018-07-29/report?format=pdf
-
Get response:
-
View generated document
⚡️ Hacks and Tips:
- Parameters are always treated as strings.
- Serve any media type by using
X-Content-Source response header.
- With
X-Content-Source response header you can use also http://, https://, file://, and data:// URLs.
💡 See Also:
|
Generate OpenAPI JSON/YAML spec from dump
-
Prepare file
dump.txt:
GET /api/customers/{id}/profile?mode=* HTTP/1.1
X-OpenAPI-Summary: Customer profile
X-OpenAPI-Description: Customer profile info
X-OpenAPI-Tags: Customers, Info
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "${request.parameters.id[0]}",
"mode": "${request.parameters.mode[0]}",
"fname": "John",
"lname": "Doe"
}
-
Print OpenAPI spec JSON to stdout:
java -jar df.jar --print-openapi --openapi-title 'Acme-CRM REST API v1.2.3' --dump dump.txt
⚡️ Hacks and Tips:
- Use
--format yaml option to print OpenAPI spec in YAML format.
- Use
--no-color option to disable ANSI colors.
- Use
--openapi-path <path> option to serve built-in OpenAPI client.
|
Basic Authentication
-
Prepare file
dump.txt:
GET /auth HTTP/1.1
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE html>
<html lang="en">
<body>
Hello Aladdin!
</body>
</html>
GET /auth HTTP/1.1
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Aladdin's secret page"
-
Start server:
java -jar df.jar --dump dump.txt
-
Navigate to:
http://localhost:8080/auth
-
In browser's authentication dialog type:
User: Aladdin
Password: open sesame
|
-
Get response:
Hello Aladdin!
⚡️ Hacks and Tips:
- Don't miss a single carriage return between headers and body!
|
Couldn't find an example for your use case? Create a new issue!
