diff --git a/README.md b/README.md index ea345be..91afa26 100644 --- a/README.md +++ b/README.md @@ -5,29 +5,129 @@ ## Usage - Usage: +``` +httpcat [OPTIONS] - Client mode - httpcat -client [options] http://uri-to-send-request-to.com +Application Options: + -v, --verbose Show additional details + --headers Show headers and request/status line only (default is everything) + --bodies Show bodies only (default is everything) + --nocolour Don't use colours (default is requests are blue and responses are red) + --notimestamps Don't show timestamps - Currently only supports GET requests. +Help Options: + -h, --help Show this help message - Server mode - httpcat -server [options] +Available commands: + client Send an HTTP request + proxy Start a reverse HTTP logging proxy + server Start a mock HTTP server + version Display version +``` - Options (either mode) - -entire or -e : Display entire request/response instead of just the body. - -verbose or -v : Be verbose. +Get help about a specific command by adding `--help` after the command. Example: - Options (client mode only) - -accept or -a [accept string] : Adds 'Accept' header to request. +``` +httpcat client --help +``` - Options (server mode only) - -body or -b [body message] : Body to respond with. Response code will default to 200. - -port or -p [port] : Port to listen on. - -response or -r [response code] : Status code to respond with. Defaults to 204. - -cors or -c : Enable Cross Origin Resource Sharing support. - -separator or -s [separator string] : Use the provided separator to separate messages. +## Client Mode + +Sends a request to the specified server and displays the response. + +### Usage + +``` +httpcat [OPTIONS] client [client-OPTIONS] + +Application Options: + -v, --verbose Show additional details + --headers Show headers and request/status line only (default is everything) + --bodies Show bodies only (default is everything) + --nocolour Don't use colours (default is requests are blue and responses are red) + --notimestamps Don't show timestamps + +Help Options: + -h, --help Show this help message + +[client command options] + -u, --uri= The URI to send the request to + --header= A header to add to request in the form name:value. Use multiple times for multiple headers. + -m, --method= HTTP method for request (default: GET) + -b, --body= Request body to send +``` + +### Example + +``` +httpcat client --method POST --body TESTING --uri http://localhost:8080/api/testing +``` + +## Server Mode + +Creates mock routes that listen on specific paths and return specific response bodies. Displays the details of any requests that it receives. + +### Usage + +``` +httpcat [OPTIONS] server [server-OPTIONS] + +Application Options: + -v, --verbose Show additional details + --headers Show headers and request/status line only (default is everything) + --bodies Show bodies only (default is everything) + --nocolour Don't use colours (default is requests are blue and responses are red) + --notimestamps Don't show timestamps + +Help Options: + -h, --help Show this help message + +[server command options] + -p, --port= Port to listen on. (default: 8080) + -r, --route= Route which is made up of a path, a response body, and a response status, all separated by the pipe character. Repeat for additional routes. (default: /|testing|200) + -c, --cors Enable Cross Origin Resource Sharing (CORS). + -H, --header= A header to add to response in the form name:value. Repeat for additional headers. +``` + +### Example + +``` +httpcat server --port 8080 --route "/hello|Hello World|200" --header "Content-Type:text/plain" +``` + +This creates a web server that listens on port 8080 and responds to any requests to the `/hello` path with the response `Hello World` and response code `200`. Repeat the `--route` option to add more routes. + +## Proxy Mode + +Creates a reverse proxy that displays all HTTP requests and responses that pass through it. + +### Usage + +``` +httpcat [OPTIONS] proxy [proxy-OPTIONS] + +Application Options: + -v, --verbose Show additional details + --headers Show headers and request/status line only (default is everything) + --bodies Show bodies only (default is everything) + --nocolour Don't use colours (default is requests are blue and responses are red) + --notimestamps Don't show timestamps + +Help Options: + -h, --help Show this help message + +[proxy command options] + -p, --port= The port that the proxy listens on. + -t, --target= +``` + +### Example + +``` +httpcat proxy --port 8090 --target http://localhost:8080 +``` + +Any requests sent to port 8090 will be forwarded to `http://localhost:8080` and all requests and responses will be displayed. ## Building @@ -61,7 +161,3 @@ ``` GOOS=darwin GOARCH=arm64 go build -o ../httpcat-mac-arm64 ``` - -## To Do - -Add support for DELETE, PUT, and POST requests in client mode.