The httpc client is a curl-like HTTP client that supports GET and POST requests using the Selective Repeat UDP protocol.
Getting Started
Start the Router
Before using the client, ensure the router is running:
Run the Client
Launch the client application: cd Client
mvn exec:java -Dexec.mainClass= "client.CLient"
You’ll see a prompt: Enter your command..
Execute Commands
Enter httpc commands at the prompt. See examples below.
Command Structure
The basic syntax for httpc commands is:
httpc command [options] URL
All commands must start with httpc. The URL must include the port number used by your server.
Help Command
Get help information about available commands:
General Help
GET Help
POST Help
Help Output
httpc is a curl-like application but supports HTTP protocol only.
Usage:
httpc command [arguments]
The commands are:
get executes a HTTP GET request and prints the response.
post executes a HTTP POST request and prints the response.
help prints this screen.
Use "httpc help [command]" for more information about a command.
usage: httpc get [-v] [-h key:value] URL
Get executes a HTTP GET request for a given URL.
-v Prints the detail of the response such as protocol, status, and headers.
-h key:value Associates headers to HTTP Request with the format 'key:value'.
usage: httpc post [-v] [-h key:value] [-d inline-data] [-f file] URL
Post executes a HTTP POST request for a given URL with inline data or from file.
-v Prints the detail of the response such as protocol, status, and headers.
-h key:value Associates headers to HTTP Request with the format 'key:value'.
-d string Associates an inline data to the body HTTP POST request.
-f file Associates the content of a file to the body HTTP POST request
Either [-d] or [-f] can be used but not both.
GET Requests
Perform HTTP GET requests to retrieve data from the server.
Basic GET Request
httpc get http://localhost:8080/get
The URL path /get is a common endpoint for testing GET requests.
GET with Query Parameters
Query parameters are automatically appended to the /get path:
httpc get http://localhost:8080/get?name=John & age = 30
Verbose Mode
Use the -v flag to see detailed response information including headers:
httpc get -v http://localhost:8080/get
Verbose mode shows the HTTP protocol version, status code, and all response headers.
Add custom headers using the -h flag:
httpc get -h Authorization:Bearer-token123 http://localhost:8080/get
Include multiple headers by repeating the -h flag:
httpc get -h Content-Type:application/json -h Accept:application/json http://localhost:8080/get
Complete GET Example
httpc get -v -h User-Agent:httpc/1.0 -h Accept:application/json http://localhost:8080/get?query=test
POST Requests
Send data to the server using HTTP POST requests.
POST with Inline Data
Use the -d flag to send inline data:
httpc post -d '{"name":"John","age":30}' http://localhost:8080/post
The client automatically adds a Content-Length header based on the data size.
POST with Data from File
Use the -f flag to read data from a file:
httpc post -f data.json http://localhost:8080/post
Either -d or -f can be used, but not both simultaneously.
Add custom headers to POST requests:
httpc post -h Content-Type:application/json -d '{"key":"value"}' http://localhost:8080/post
Verbose POST
See detailed response information:
httpc post -v -d 'test data' http://localhost:8080/post
Complete POST Example
httpc post -v -h Content-Type:application/json -h Authorization:Bearer-xyz -d '{"message":"Hello World"}' http://localhost:8080/post
Output Options
Write Response to File
Use the -o flag to save the response to a file:
httpc get -o output.txt http://localhost:8080/get
This is useful for saving large responses or when you need to process the output later.
Console Output
By default, responses are printed to the console. Without verbose mode, only the response body is shown:
httpc get http://localhost:8080/get
With verbose mode, headers and status are included:
httpc get -v http://localhost:8080/get
Command Options Reference
Prints detailed response information including protocol, status, and headers.
Associates headers to the HTTP request in the format key:value. Can be used multiple times.
Associates inline data to the HTTP POST request body. Cannot be used with -f.
Reads data from a file for the HTTP POST request body. Cannot be used with -d.
Writes the response to the specified file instead of printing to console.
Connection Flow
When you execute a command, the client:
Establishes Connection
The client connects to the server through the router using a three-way handshake.
Sends Request
Once connected, the request is sent using the Selective Repeat protocol. Connection established, sending request
Receives Response
The client receives the response packets and reassembles them.
Displays Output
The response is parsed and displayed according to the specified options.
Real-World Examples
API Testing
File Upload
Authentication
Debug Mode
Test a JSON API endpoint: httpc get -v -h Content-Type:application/json -h Accept:application/json http://localhost:8080/get?id= 123
Upload a JSON file: httpc post -h Content-Type:application/json -f payload.json http://localhost:8080/post
Make an authenticated request: httpc get -h Authorization:Bearer-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 http://localhost:8080/get
Debug a failing request: httpc post -v -h Content-Type:application/json -d '{"debug":true}' http://localhost:8080/post
Interactive Mode
The client runs in interactive mode, allowing multiple requests:
mvn exec:java -Dexec.mainClass= "client.CLient"
Enter your command..
httpc get http://localhost:8080/get
[Response displayed]
do you want to continue?
yes
Enter your command..
httpc post -d 'test' http://localhost:8080/post
[Response displayed]
do you want to continue?
no
Type “yes” to continue making requests or “no” to exit the client.
Troubleshooting
Ensure the router and server are running: # Terminal 1: Start router
./router --port 3000
# Terminal 2: Start server
cd Server
mvn exec:java -Dexec.mainClass= "Server.ServerCommand"
httpfs -p 8080
Make sure your URL includes the protocol and port: # Correct
httpc get http://localhost:8080/get
# Incorrect
httpc get localhost/get
When using -f, ensure the file path is correct: # Use absolute or relative path
httpc post -f ./data.json http://localhost:8080/post
httpc post -f /home/user/data.json http://localhost:8080/post
Next Steps
Server Setup Learn how to set up the httpfs server
Router Configuration Configure network conditions for testing