Skip to main content

HTTP Client

Assignment: HTTP Client Command-line program

Goal

Create a HTTP client command-line program using Go Programming language.

Requirements

  1. Use Go Programming Language
  2. Program name is httpcli
  3. Have these following sub-commands
    • get: send a GET request to a given URL.
    • post: send a POST request to a given URL.
    • put: send a PUT request to a given URL.
    • delete: send a DELETE request to a given URL.
  4. Calling the program without a sub-command should send a GET request to a URL.
  5. After calling a command, prints the result to STDOUT (terminal).

Command descriptions

global flags

The following flags should be available in all sub-commands.

  1. --help: Print help message e.g. how to use the program and sub-commands.

  2. --query: Construct query parameters of the GET request.

    Command should be able to handle multiple query flags. For example, httpcli get someweb.com --query key1=value1 --query key2=value2

  3. --header: Construct headers of the GET request.

    Command should be able to handle multiple header flags. For example, httpcli get someweb.com --header key1=value1 --header key2=value2

root command

Expected usage

httpcli [SUB-COMMAND] <URL> [FLAGS...]
  1. Calling the root command should send a GET request to a URL. For example, httpcli google.com.

get sub-command

Expected usage

httpcli get <URL> [FLAGS...]

post sub-command

Expected usage

httpcli post <URL> [FLAGS...]
  1. --json: Construct JSON body of the POST request.

    Command should also validate JSON input whether it is correct or not.

    Example usage

    httpcli post someweb.com --json "{ 'key': 'value' }"

delete sub-command

Expected usage

httpcli delete <URL> [FLAGS...]

put sub-command

Expected usage

httpcli put <URL> [FLAGS...]
  1. --json: Construct JSON body of the POST request.

    Command should also validate JSON input whether it is correct or not.

    Example usage

    httpcli post someweb.com --json "{ 'key': 'value' }"

Useful resources