Git Product home page Git Product logo

deepfakehttp's Introduction






YOUR 100% STATIC DYNAMIC BACKEND

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 | Usage | Usage Examples | How does it work? | Features | Optional Headers | CLI | Cheatsheet

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": ["[email protected]", "[email protected]"]
    }
    
  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.
Also take look at REST version of the Spring PetClinic built with DeepfakeHTTP.

Usage

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

Usage Examples

Start server on dump file:
java -jar df.jar --dump dump.txt
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 with built-in OpenAPI client with custom title:
java -jar df.jar --openapi-path /api --openapi-title 'My 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
If you still need examples make sure to check out the cheatsheet.

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 404.
That's all.

Features

    ✓  no dependencies
    ✓  no installation
    ✓  no configs
    ✓  crossplatform
    ✓  single-file executable
    ✓  command-line interface

more features…
    ✓  fully asynchronous
    ✓  HTTP message formats RFC 7230
    ✓  multiple entries per dump
    ✓  multiple request/response entries per dump
    ✓  extracts responses from HTTP dumps
    ✓  self-hosted built-in OpenAPI client
    ✓  exportable persistent memory
    ✓  persistent data
    ✓  CGI, XGI and JavaScript handlers
    ✓  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
    ✓  body fetching from external sources like URLs, local files, and data URI
    ✓  per entry user-defined request/response delays
    ✓  comments # in dumps
    ✓  live request/response collection
    ✓  watching dump files for changes
    ✓  ETag support
    ✓  CORS support
    ✓  live request/response logging
    ✓  TLS(SSL) connections and HTTP to HTTPS redirect
    ✓  customizable OpenAPI client path
    ✓  latest OpenAPI specification v3.0.3 support
    ✓  colorized console output
    ✓  disabling color via command line or NO_COLOR environment variable

LICENSE

The DeepfakeHTTP is released under the MIT license.



APPENDIX A.
Command line options

OptionDefaultDescription
--host <host name> localhost host name, default: localhost

See Also:
       --port <number>
       --port-ssl <number>
       --redirect
--port <number> 8080 HTTP TCP port number, default: 8080

See Also:
       --port-ssl <number>
       --redirect
       --host <host name>
--port-ssl <number> 8443 HTTPS TCP port number, default: 8443
Create TLS(SSL) connection based on built-in self-signed certificate

See Also:
       --port <number>
       --redirect
       --host <host name>
--dump <file|url>... Dump text file(s)/URL(s)
--db <file|url>... JSON/YAML/CSV memory file to populate templates

See Also:
       --db-export <file>
       --db-path <path>
       --no-bak
       --js <file|url>...
       X-Handler-JS
--db-export <file> Export memory to JSON file

See Also:
       --db <file|url>...
       --db-path <path>
       --no-bak
--db-path <path> Serve live memory file at specified context.
With this option you can view or export the memory state in JSON format.

See Also:
       --db <file|url>...
       --db-export <file>
       --no-bak
--dir <dir> Forward unmatched requests to specified directory.

See Also:
       --dump <file|url>...
--js <file|url>... JavaScript file(s) for script engine context.

See Also:
       X-Handler-JS
       --db <file|url>...
--openapi-path <path> Serve built-in OpenAPI client at specified context

See Also:
       --openapi-title <text>
       --print-openapi
       X-OpenAPI-Summary
       X-OpenAPI-Description
       X-OpenAPI-Tags
       X-OpenAPI-Parameters
--openapi-title <text> Provide custom OpenAPI specification title

See Also:
       --openapi-path <path>
       --print-openapi
       X-OpenAPI-Summary
       X-OpenAPI-Description
       X-OpenAPI-Tags
       X-OpenAPI-Parameters
--collect <file> Collect live request/response to file
--format <json|yaml> json Output format for --print-* commands, default: json
--status <number> 404 Status code for non-matching requests, default: 404
--max-log-body <number> Max body bytes in console log, default: unlimited

See Also:
       --no-log
       --no-log-body
       --no-log-headers
--no-log Disable request/response console logging

See Also:
       --no-log-request-info
       --no-log-body
       --max-log-body <number>
       --no-log-headers
--no-log-request-info Disable request info in console logging

See Also:
       --no-log
       --no-log-body
       --max-log-body <number>
       --no-log-headers
--no-log-headers Disable request/response headers in console logging

See Also:
       --no-log
       --no-log-request-info
       --no-log-body
       --max-log-body <number>
--no-log-body Disable request/response body in console logging

See Also:
       --max-log-body <number>
       --no-log
       --no-log-request-info
       --no-log-headers
--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
ANSI color output also can be disabled via NO_COLOR environment variable.

See Also:
       --no-pretty
--no-pretty Disable prettyprint for --print-* commands

See Also:
       --no-color
--no-template Disable template processing
--no-wildcard Disable wildcard processing.
By default wildcard processing is enabled.
The asterisk * represents one or more characters, the question mark ? represents a single character, and / represents escape character.
--no-bak Disable backup old memory file before overwrite.
The memory file is overwritten every time the server shuts down.

See Also:
       --db <file|url>...
       --db-export <file>
       --db-path <path>
--strict-json Enable strict (byte by byte) JSON comparison
--redirect Enable redirect HTTP to HTTPS

See Also:
       --port <number>
       --port-ssl <number>
       --host <host name>
--help Print help message
--print-info Print dump files statistics to stdout as json/yaml

See Also:
       --format <json|yaml>
       --no-color
       --no-pretty
--print-requests Print dump requests to stdout as json/yaml

See Also:
       --format <json|yaml>
       --no-color
       --no-pretty
--print-openapi Print OpenAPI specification to stdout as json/yaml

See Also:
       --openapi-path <path>
       --openapi-title <text>
       --format <json|yaml>
       --no-color
       --no-pretty



APPENDIX B.
Optional REQUEST / RESPONSE headers

HeaderDescription
X-Delay

Request or response delay (in milliseconds).

Examples:

Two seconds request delay:

GET / HTTP/1.1
X-Delay: 2000

Two seconds response delay:

HTTP/1.1 200 OK
X-Delay: 2000
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-OpenAPI-Summary

OpenAPI request summary text.

Example:
GET /api/customer{id} HTTP/1.1
X-OpenAPI-Summary: Get customer information


See Also:
       X-OpenAPI-Description
       X-OpenAPI-Tags
       X-OpenAPI-Parameters

X-OpenAPI-Description
OpenAPI request description text.

Example:
GET /api/customer{id} HTTP/1.1
X-OpenAPI-Summary: Get customer information
X-OpenAPI-Description: This API extracts customer info from db


See Also:
       X-OpenAPI-Summary
       X-OpenAPI-Tags
       X-OpenAPI-Parameters

X-OpenAPI-Tags
OpenAPI request comma-separated tag list.

Example:
GET /api/customer{id} HTTP/1.1
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


See Also:
       X-OpenAPI-Summary
       X-OpenAPI-Description
       X-OpenAPI-Parameters

X-OpenAPI-Parameters
OpenAPI request parameters information.

Example:
GET /api/customer{id} HTTP/1.1
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
X-OpenAPI-Parameters: name=cust_id;description=Customer ID,
 name=rdate;description=Review Date


See Also:
       X-OpenAPI-Summary
       X-OpenAPI-Description
       X-OpenAPI-Tags

X-Forward-To
Forward client request to specified origin.

Acts as a forward proxy.

Example:
HTTP/1.1
X-Forward-To: http://example.com:8080
X-Handler-CGI
CGI (Common Gateway Interface) program.

Example:
HTTP/1.1 200 OK
X-Handler-CGI: /home/john/myprog.sh param1 param2


See Also:
       X-Handler-XGI
       X-Handler-JS

X-Handler-XGI
XGI (Extended Gateway Interface) program.

XGI program is very similar to CGI, but unlike CGI, the XGI program reads from stdin not only the body of the request but also the first line and the headers. In response XGI program writes status line, headers and response body into stdout.
All CGI environment variables are also available to XGI program.

Example:
HTTP/1.1
X-XGI: /home/john/myprog.sh param1 param2


See Also:
       X-Handler-CGI
       X-Handler-JS

X-Handler-JS
JavaScript response handler function.

The JavaScript functions are taken from the context files listed in the
--js <file|url>... option.

The following objects are provided as handler function parameters:
  • request - object, READ ONLY
    • request.method: string E.g. request.methodpost
    • request.path: string E.g. request.path/api/customers
    • request.query: string E.g. request.queryfname=John&lname=Doe
    • request.parameters: object E.g. request.parameters.fname[0]John
    • headers: object E.g. request.headers['content-type'][0]application/json
    • request.body: string | object E.g. request.body{"fname": "Jonh", lname: "Doe"}
  • response - object, READ | WRITE
    • response.status: number E.g. response.status = 200
    • response.headers: object E.g. response.headers['Content-Type'] = 'application/json'
    • response.body: string | object E.g. response.body = {"fname": "Jonh", lname: "Doe"}
  • data: object, READ | WRITE - persistent user data from the file provided by --db option
Among other things, the X-Handler-JS header allows you to modify persistent data.

Examples:

JavaScript function modify memory data:

DELETE /customers/{id}

HTTP/1.1 200 OK
X-Handler-JS: deleteCustomer
Content-Type: application/json

{"id": "${request.parameters.id[0]}"};

function deleteCustomer(request, response, data) {
    const id = request.parameters.id[0];
    delete data.customers[id];
}

JavaScript function modify memory data and provide response status, headers and body:
DELETE /customers/{id}

HTTP/1.1
X-Handler-JS: deleteCustomer

function deleteCustomer(request, response, data) {
    const id = request.parameters.id[0];
    if (data.customers[id] === undefined) {
        response.status = 404;
        response.body = {error: true, message: 'ID not found'};
    }
    delete data.customers[id];
    response.status = 200;
    response.headers['Content-Type'] = 'application/json';
    response.body = {error: false, message: null};
}


See Also:
       --js <file|url>...
       --db <file|url>...
       X-Handler-CGI
       X-Handler-XGI


NOTE:
            1. Optional request headers will not be sent to the server engine.
            2. Optional response headers will not be sent to clients.

deepfakehttp's People

Contributors

4e1e0603 avatar lgyurci avatar xnbox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deepfakehttp's Issues

Feature suggestion: reflect request

I came across this as a testing tool. It's nice, thanks. Another testing desire I have occasionally is to run an on line webserver temporarily that just responds with a complete and reliable description of the request it received. A request mirror. To test both the construction of and transport of requests I guess. Wonder if this is a nice tool to add that to, or if another exists that I've not found.

Where's the AI part of it?

Given the name, I was expecting that you'd use AI to implement a fancy mock HTTP server.
Turns out it's just yet another regular mock HTTP server... Reporting this as a bug in the project's name ;)

Help - How to access request body in post request?

Hi,

Dump

POST /api/customer/show HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json

{
    "id": "${request.body}",
    "name": "Name"
}

Request

http localhost:9999/api/customer/show  id=1
POST /api/customer/show HTTP/1.1
Host: localhost:9999
User-Agent: HTTPie/1.0.3
Accept-Encoding: gzip, deflate
Accept: application/json, */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 11

{"id": "1"}
--------------------------------------------------------------------------------
HTTP/1.1 200 OK
Content-Type: application/json
Server: DeepfakeHTTP v6.4.2 (2022-01-23 14:42:00)
Content-Length: 48
ETag: "85fffc49"

{
    "id": "{"id": "1"}",
    "name": "Name"
}

Expectation

Response:

{
    "id": "1",
    "name": "Name"
}

Question

What do I need to do, if I want to access the "id" key in the request body?

I tried "id": "${request.body.id}" but this returns "id": "undefined".

Versioning and releases

Hello, I feel that you didn't understand semantic versioning correctly..
I see that you released a lot of various versions (3.1.1, 3.2.1, 4.1.1, 5.1.1) during last two weeks.

But semantic versioning is in format: MAJOR.MINOR.PATCH which is increased without too big jumping.
For example when you have version: 2.1.1
And when you add 3 bug fixes so next version will be: 2.1.2
When you add 3 bug fixes and 2 features so next version will be: 2.2.0
When you add 3 bug fixes and 4 features but one from your change will not compatible with some previous version
(for example you can remove some big functionality or you can rewrite all your code with some BREAK changes)
so next version will be: 3.0.0

I also very recommend make releases in longer interval. For example when you make release every second or third day with small changes, it is too often. Much better is when you make release with new features only one per month.
And change MAJOR version only one per year.

If you want to make releases more often, you can release it as RC (Release candidate) version:
2.2.0-rc.1
And release candidate you can release only one per 1 week so during one month you will release max. only 4 RC versions.

Do you understand me?

Feature Suggestion: Traffic interceptor

Hi, I really liked this project. I think that the "collect" mode could be more useful if it was somehow connected to some tunnel like (https://github.com/mukatee/java-tcp-tunnel), so the user could start the DeepfakeHTTP using collect to automatically generate requests and true responses from the server. I think that this would be really useful for testing some systems without depending on third party APIs/sites every time.

java.lang.NullPointerException after DeepfakeHTTP start

Hi,

my startup gives me the following response. Everything works fine, but I am curious about the java.lang.NullPointerException after the DeepfakeHTTP start.

Using Ubuntu's openjdk-17-jdk-headless package.

❯ java -jar df-6.4.2.jar --dump dump.txt 
2022-01-25 13:13:46 INFO   Cluster RuleSet not found due to [java.lang.ClassNotFoundException: org.apache.catalina.ha.ClusterRuleSet]. Cluster configuration disabled.
2022-01-25 13:13:46 INFO   Cluster RuleSet not found due to [java.lang.ClassNotFoundException: org.apache.catalina.ha.ClusterRuleSet]. Cluster configuration disabled.
2022-01-25 13:13:46 INFO   Server version name:   Apache Tomcat/10.0.10
2022-01-25 13:13:46 INFO   Server built:          Jul 30 2021 09:51:27 UTC
2022-01-25 13:13:46 INFO   Server version number: 10.0.10.0
2022-01-25 13:13:46 INFO   OS Name:               Linux
2022-01-25 13:13:46 INFO   OS Version:            5.13.0-27-generic
2022-01-25 13:13:46 INFO   Architecture:          amd64
2022-01-25 13:13:46 INFO   Java Home:             /usr/lib/jvm/java-17-openjdk-amd64
2022-01-25 13:13:46 INFO   JVM Version:           17.0.1+12-Ubuntu-120.04
2022-01-25 13:13:46 INFO   JVM Vendor:            Private Build
2022-01-25 13:13:46 INFO   CATALINA_BASE:         /tmp/catalina_base-9622103583921507216
2022-01-25 13:13:46 INFO   CATALINA_HOME:         /tmp/catalina_home-17115209648337543168
2022-01-25 13:13:46 INFO   The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2022-01-25 13:13:47 INFO   Initializing ProtocolHandler ["http-nio-8080"]
2022-01-25 13:13:47 INFO   Server initialization in [1493] milliseconds
2022-01-25 13:13:47 WARNING A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
2022-01-25 13:13:47 INFO   Starting service [Catalina]
2022-01-25 13:13:47 INFO   Starting Servlet engine: [Apache Tomcat/10.0.10]
2022-01-25 13:13:48 INFO   Unknown class loader [jdk.internal.loader.ClassLoaders$PlatformClassLoader@6009e3f5] of class [class jdk.internal.loader.ClassLoaders$PlatformClassLoader]
2022-01-25 13:13:53 INFO   At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2022-01-25 13:13:53 INFO   DeepfakeHTTP Logger: HELLO!
2022-01-25 13:13:53 INFO   File: "dump.txt" found 1 entries.
2022-01-25 13:13:53 INFO   1 file(s) processed. 1 entries found.
2022-01-25 13:13:53 INFO   1 dump file(s) loaded.
2022-01-25 13:13:53 INFO   0 JavaScript file(s) loaded.
2022-01-25 13:13:53 INFO   Data file loaded.
DeepfakeHTTP started.
java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.register(java.nio.file.WatchService, java.nio.file.WatchEvent$Kind[])" because "this.dirPath" is null
        at org.deepfake_http.common.dir_watcher.DirectoryWatcher.run(DirectoryWatcher.java:53)
        at java.base/java.lang.Thread.run(Thread.java:833)
Starting ProtocolHandler ["http-nio-8080"]
Tommy started.

Test:

❯ http http://localhost:8080/api/customer/123
HTTP/1.1 200 
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 117
Content-Type: application/json
Date: Tue, 25 Jan 2022 12:18:48 GMT
ETag: "f97ade2e"
Keep-Alive: timeout=20
Server: DeepfakeHTTP v6.4.2 (2022-01-23 14:42:00)

{
    "email": [
        "[email protected]",
        "[email protected]"
    ],
    "fname": "John",
    "id": 123,
    "lname": "Doe"
}

Options are detected as files

When I run command:

java -jar ~/Downloads/df-1.0.8.jar --port 3000 /home/martin/Projects/my-project/endpoints/*

So Deepfake detect argument --port 3000 as file inputs:
image

POST request with Content-Type: application/json

Can you show me example how to fake POST request with Content-Type: application/json?
For this curl?:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"username":"xyz","password":"xyz"}' \
  http://localhost:3000/api/login

response can be also Content-Type: application/json
for example:
{
"name": "Martin",
"surname: "Jablecnik",
"logged_in: true
}

In your examples I see only GET for Content-Type: application/json and POST for Content-Type: application/x-www-form-urlencoded

Thank you very much.

Refactoring and tests

Hello @xnbox I found your DeebfakeHTTP project here and it looks very nice 👍
You created nice tool with good documentation and probably I will be use it ;-)

But when I look into your code so I can really recommend you to read Clean Code book by Robert C. Martin.
Because I found that you need it.

Then I really recommend you to go through your projects and made refactor because in DeepfakeHttpServlet you have very big doDbRequest function which can be splited into more smaller functions for better readability.
I tried understand it for future contribution but it is very hard to read and understand for me..

The same you can make also in your other projects for example BrowserWindow.java intommybox project you have really big launch function or createMenu function..

Also you should create some tests for ensure that after your refactor works everything right.

Without this changes will be very hard for other developers like me to understand your code and make some changes and PRs in the future..

I hope it will be improved and your project will be successful in the Open Source world. ;-)

Trim blank lines of response

My responses have some blank lines on end of every response:
image

Blank lines should be trim before send of response.

Configurable log verbose

Exists some possibility how to show in stdout only one line requests and more detailed information about request/response move into some special log file? Or show it only with -v, -vv, -vvv verbose tags.
I think there is too a lot of information in stdout per every request for now but I don't want to disable it..

Custom separator

Hello, I want to use my own custom separator instead of '.'
but when I add '#---' so it doesn't work.
Do you know why?
I have there '#' for make as comment it..

Here is example of my file:

#---

POST /dapi/v1/inventory/item/EAN123/save HTTP/1.1

{"items":["SN123","SN124","SN125","SN126"]}

HTTP/1.1 200 OK

#---

GET /dapi/v1/inventory/item/SN123/check HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json

{
  "in_stock": true
}

#---

GET /dapi/v1/inventory/item/SN123/location HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json

{
  "location": {
    "code": "1-2-3A",
    "name": "L123A"
  }
}

#---

My version is: 1.0.14

New --data option question

Hello @xnbox,
I see that you added a new --data option into DeepfakeHTTP but I didn't found any example of how to use it..
Can you write here some description of this new functionality please? I tried understand it but I am not sure if I understand it right.
Can you write here also some small example? Thank you very much for your work. :-)

Option for change default response

Hello, I know that when I send request for not existing endpoint so I gain 400 Bad request error response.
But what to do when I want to have some another default response? For example 404 Not found?

Exists some option which can change what DeepfakeHTTP return when the endpoint doesn't exists?

Project setup documentation for developers

Hello, I would like to help you with this project in my free time but I don't know how to start..
I have IntelliJ Idea Community Edition 2020.3, Java SDK version 17, cloned latest version of this repository and my setup configuration is here:
image

But when I run it so I gain only this:
image

And I don't know how to setup it correctly..

Can you write some documentation for developers about how to setup this project and how to build it?
Are you using Maven or Gradle build tool? I don't see any configurations for this tools in the project..

Thank you very much.. :-)

How to configure https to work?

Hi! When I start the project, I have an notice saying that "The Apache Tomcat Native library which allows using OpenSSL was not found on the java." This is no problem for me (it's a little bit anoying that it prints mt entire path after that, but no problem)

But the real problem is when I try to point to my dfHttp as if it used https, so using "https://localhost:8080" instead of "http://localhost:8080" when this happens, it print an error and a stacktrace. I guess that this is not so intuitive for who is using
image

Comments behind of text

It would be nice to have also comments starting in the middle of line after some text.

For example I can have this endpoint:

#
# Login endpoint
#
POST /login HTTP/1.1
Content-Type: application/json

{"username":"xyz","password":"xyz"}

HTTP/1.1 200 OK
Content-Type: application/json

{
    "name":"Martin",          # here is user name
    "surname":"Jablecnik"     # here is user surname
}

where I have to comment my fields of output body but I don't want to have it in the real output:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.