diff --git a/README.md b/README.md index 79521fb..865ea86 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,10 @@ ### Usage ``` -httpcat client [OPTIONS] +httpcat client [OPTIONS] URL ``` ### Client Specific Options ``` --u, --url= The URL to send the request to. - -H, --header= A header to add to request in the form name:value. Use multiple times for multiple headers. @@ -71,16 +69,14 @@ --body "Testing 123" \ --header "Content-Type: text/plain" \ --header "Authorization: Bearer abc123" \ - --uri http://localhost:8080/api/testing + http://localhost:8080/api/testing ``` -Note that the `\` character in the above example is the line continuation character that allows you to break long lines into smaller lines in most Linux/macOS shells. - -For the Windows `cmd` shell, use `^` for line continuation. For PowerShell, use ` (the backtick character). +Note that the `\` character in the above example is the line continuation character that allows you to break long lines into smaller lines in most Linux/macOS shells. For the Windows `cmd` shell, use `^` for line continuation. For PowerShell, use ` (the backtick character). ## Server Mode -Creates a web server with mock routes that listen on specific paths and return specific response bodies. Displays the details of any requests that it receives. +Creates a web server with mock routes that listen on specific paths and return specific responses. Displays the details of any requests that it receives. ### Usage @@ -95,7 +91,7 @@ -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 123|200). + Repeat for additional routes. -c, --cors Enable Cross Origin Resource Sharing (CORS). Allows all requested methods and headers. @@ -106,16 +102,63 @@ ### Example +Linus/macOS: ``` httpcat server \ --port 8080 \ - --route "/hello|Hello World|200" \ - --route "/goodbye||204" \ - --header "Content-Type: text/plain" \ + --route "/hello|Hello World|text/plain|200" \ + --route "/goodbye|||204" \ --cors ``` -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`, and returns an empty response with a `204` code to any requests made to `/goodbye`. The server will allow any requested headers and methods for CORS requests. +Windows PowerShell: +``` +httpcat server ` + /port:8080 ` + /route:"/hello|Hello World|text/plain|200" ` + /route:"/goodbye|||204" ` + /cors +``` + +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`, and returns an empty response with a `204` response code to any requests made to `/goodbye`. The server will allow any requested headers and methods for CORS requests. + +### Server Wildcard Mode + +If no routes are specified then the server will accept requests to all paths, returning a `200` response code with an empty body for `GET` requests and a `204` response code for all other request methods. + +### Complex Bodies + +For mocking real web services it can be annoying to include a large body directly in the route definition. A better option is to use shell command substitution to load the body from a file: + +File `cust.json`: +``` +{ + "data": { + "id": "0266a95f-e57c-11ec-f37b-c20db6f2e117", + "customer_code": "Boris-SVZ7", + "first_name": "Boris", + "last_name": "McNorris", + "email": "boris@example.com", + "customer_group_id": "0afa8de1-147c-11e8-edec-2b197906d816" + } +} +``` + +Linux/macOS: +``` +httpcat server \ + --port 8080 \ + --route "/api/2.0/customers|$(cat cust.json)|application/json|201" \ + --cors +``` + +Windows PowerShell: +``` +httpcat server ` + /port:8080 ` + /route:"/api/2.0/customers|$(gc cust.json)|application/json|201" ` + /cors +``` ## Proxy Mode @@ -130,7 +173,9 @@ ### Proxy Specific Options ``` -p, --port= The port that the proxy listens on. --t, --target= + +-t, --target= The URL for the target web server that the proxy forwards + requests to. ``` ### Example