Compare commits

..

4 commits

Author SHA1 Message Date
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
2 changed files with 8 additions and 5 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) ![license](https://licensebuttons.net/p/zero/1.0/88x31.png)

11
curl.sh
View file

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# Check if the correct number of arguments is provided # Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then if [ -z "${1:-}" ]; then
echo "Usage: $0 <url> <request_method>" echo "Usage: $0 <url> [request_method]"
exit 1 exit 1
fi fi
@ -17,7 +17,7 @@ RESP_BODY_RAW_FILE="curl/resp_body.txt"
RESP_BODY_JSON_FILE="curl/resp_body.json" RESP_BODY_JSON_FILE="curl/resp_body.json"
url="$1" url="$1"
method="$2" method="${2:-GET}"
# Append url search parameters # Append url search parameters
if [ -f $REQ_PARAMS_FILE ]; then if [ -f $REQ_PARAMS_FILE ]; then
@ -66,8 +66,11 @@ curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
# Execute curl # Execute curl
eval "clear" eval "clear"
echo -e "${method} ${url}" echo -e "\e[0;92mRequest >\e[0m ${method} ${url}"
eval $curl_cmd eval $curl_cmd
# Copy the raw respone body to a pretty-printed JSON file # Copy the raw respone body to a pretty-printed JSON file
jq . $RESP_BODY_RAW_FILE > $RESP_BODY_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