HTTP Client
Assignment: HTTP Client Command-line program
Goal
Create a HTTP client command-line program using Go Programming language.
Requirements
- Use Go Programming Language
- Program name is
httpcli - 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.
- Calling the program without a sub-command should send a GET request to a URL.
- After calling a command, prints the result to STDOUT (terminal).
Command descriptions
global flags
The following flags should be available in all sub-commands.
-
--help: Print help message e.g. how to use the program and sub-commands. -
--query: Construct query parameters of the GET request.Command should be able to handle multiple
queryflags. For example,httpcli get someweb.com --query key1=value1 --query key2=value2 -
--header: Construct headers of the GET request.Command should be able to handle multiple
headerflags. For example,httpcli get someweb.com --header key1=value1 --header key2=value2
root command
Expected usage
httpcli [SUB-COMMAND] <URL> [FLAGS...]
- 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...]
-
--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...]
-
--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' }"
Recommended Go Libraries
- CLI libraries (Pick one)
- HTTP library (Pick one)
Useful resources
- What are REST APIs?
- REST APIs in 100 Seconds
- HTTP protocol basics
- For beginners, we recommend you to play around with other HTTP clients first to familiarize yourself with it. For example, HTTPie is one of the clients you can use.