Compare commits

...

8 commits

Author SHA1 Message Date
64db42527b refactor: preserve terminal screen and scrollbuffer (#13)
Maintain the terminal output. If clearing the screen and scrollbuffer is desired, it should be wrapped in an upstream script.

Reviewed-on: https://codeberg.org/vlw/curl/pulls/13
2026-04-12 10:42:17 +02:00
29090ad555 fix: append search parameters to URL only if set (#14)
Append search parameters to URL only if search parameters are provided. This means that "?" will not be appended to the URL if no parameters are provided.

Reviewed-on: https://codeberg.org/vlw/curl/pulls/14
2026-04-12 10:42:00 +02:00
832bea4252 fix: print first response header to CLI (#12)
Let's print the first response header in its entirety as opposed to the response code and.. the first word of the response header text. That is the main reason why we do this, let's just print the whole line.

Reviewed-on: https://codeberg.org/vlw/curl/pulls/12
2026-04-06 11:31:39 +02:00
7b70a6e51d fix: accept at least one argument (#11)
We should accept at least one argument since we made the second argument optional in #9

Reviewed-on: https://codeberg.org/vlw/curl/pulls/11
2026-04-06 11:17:12 +02:00
vlw
e015174467 feat: print response code to CLI (#10)
Closes #8

Reviewed-on: https://codeberg.org/vlw/curl/pulls/10
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2026-04-06 10:25:27 +02:00
328cebc703 feat: default method to GET if not provided (#9)
Set the default request method to `GET` if no method is provided

Reviewed-on: https://codeberg.org/vlw/curl/pulls/9
2026-04-06 10:25:07 +02:00
a42be0792c docs: echo success message when new config is generated (#7)
Reviewed-on: https://codeberg.org/vlw/curl/pulls/7
2026-03-31 12:02:26 +02:00
dfd0664255 style: use lower case for variables (#6)
Use lower case for variables and upper case for constants to follow common conventions.

Reviewed-on: https://codeberg.org/vlw/curl/pulls/6
2026-03-31 12:02:06 +02:00
3 changed files with 32 additions and 24 deletions

View file

@ -1,4 +1,4 @@
![screenshot](https://codeberg.org/attachments/1cae98c6-0873-41fd-aad0-d33bf495fc50)
![curl-screenshot](https://codeberg.org/attachments/9bdd8005-5eea-4add-89c3-8efc61d06b6f)
![license](https://licensebuttons.net/p/zero/1.0/88x31.png)

52
curl.sh
View file

@ -1,14 +1,11 @@
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <url> <request_method>"
if [ -z "${1:-}" ]; then
echo "Usage: $0 <url> [request_method]"
exit 1
fi
URL="$1"
METHOD="$2"
DISABLE_SSL_FILE="disable_peer_validation"
REQ_BODY_FILE="curl/req_body.json"
@ -19,39 +16,47 @@ RESP_HEADERS_FILE="curl/resp_headers.txt"
RESP_BODY_RAW_FILE="curl/resp_body.txt"
RESP_BODY_JSON_FILE="curl/resp_body.json"
# Append URL search parameters
url="$1"
method="${2:-GET}"
# Append url search parameters
if [ -f $REQ_PARAMS_FILE ]; then
# Parse each newline as a separate parameter joined by a "&"
PARAMS=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
URL="${URL}?${PARAMS}"
params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
if [ -n "$params" ]; then
url="${url}?${params}"
fi
fi
# Prepare curl
CURL_CMD="curl -s"
curl_cmd="curl -s"
# Check if SSL peer validation should be disabled
if [ -f $DISABLE_SSL_FILE ]; then
CURL_CMD="$CURL_CMD -k"
curl_cmd="$curl_cmd -k"
fi
# Add headers from headers.json
if [ -f $REQ_HEADERS_FILE ]; then
# Read headers from the JSON file
while IFS= read -r line; do
HEADER_NAME=$(echo "$line" | jq -r '.[keys[0]]')
HEADER_VALUE=$(echo "$line" | jq -r '.[keys[1]]')
CURL_CMD="$CURL_CMD -H \"$HEADER_NAME: $HEADER_VALUE\""
header_name=$(echo "$line" | jq -r '.[keys[0]]')
header_value=$(echo "$line" | jq -r '.[keys[1]]')
curl_cmd="$curl_cmd -H \"$header_name: $header_value\""
done < <(jq -c 'to_entries | .[]' "$REQ_HEADERS_FILE")
fi
# Add the request method and URL to curl
CURL_CMD="$CURL_CMD -X $METHOD \"$URL\""
curl_cmd="$curl_cmd -X $method \"$url\""
# If the method is not GET, include the payload
if [ $METHOD != "GET" ]; then
if [ $method != "GET" ]; then
if [ -f "$REQ_BODY_FILE" ]; then
PAYLOAD=$(<"$REQ_BODY_FILE")
CURL_CMD="$CURL_CMD -H \"Content-Type: application/json\" -d '$PAYLOAD'"
payload=$(<"$REQ_BODY_FILE")
curl_cmd="$curl_cmd -H \"Content-Type: application/json\" -d '$payload'"
else
echo "Error: Payload file '${REQ_BODY_FILE}' not found."
exit 1
@ -59,13 +64,14 @@ if [ $METHOD != "GET" ]; then
fi
# Save the response headers and body
CURL_CMD="$CURL_CMD -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
# Execute curl
eval "clear"
echo -e "${METHOD} ${URL}"
eval $CURL_CMD
# Dispatch request
echo -e "\e[0;92mRequest >\e[0m ${method} ${url}"
eval $curl_cmd
# Copy the raw respone body to a pretty-printed JSON file
jq . $RESP_BODY_RAW_FILE > $RESP_BODY_JSON_FILE
# Print the response code
echo -e -n "\e[0;94mResponse <\e[0m "; head -n 1 $RESP_HEADERS_FILE

View file

@ -9,3 +9,5 @@ echo "" > resp_headers.txt
echo "{}" > req_body.json
echo "{}" > resp_body.json
echo "{}" > req_headers.json
echo "New configuration created"