-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(API): accept JSON request by header
Accept: application/json
BREAKING CHANGE Before: ```sh curl 'http://server/path?json' ``` After: ```sh curl -H 'Accept: application/json' 'http://server/path' ```
- Loading branch information
1 parent
b850c4f
commit 1f6b334
Showing
6 changed files
with
77 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
#!/bin/bash | ||
|
||
assert() { | ||
expect="$2" | ||
actual="$1" | ||
local expect="$2" | ||
local actual="$1" | ||
if [ "$expect" != "$actual" ]; then | ||
echo -e "$(basename $0):${BASH_LINENO[0]} expect \"\e[0;32m$expect\e[0m\", got \"\e[1;31m$actual\e[0m\"" >&2 | ||
fi | ||
} | ||
|
||
fail() { | ||
msg="$1" | ||
local msg="$1" | ||
echo -e "$(basename $0):${BASH_LINENO[0]} \e[1;31m$msg\e[0m" >&2 | ||
} | ||
|
||
curl_head_status() { | ||
args=($@) | ||
urlindex=$[ ${#args[@]} - 1 ] | ||
opts="${args[@]:0:urlindex}" | ||
url="${args[urlindex]}" | ||
local args=("$@") | ||
local urlindex=$[ ${#args[@]} - 1 ] | ||
local opts=("${args[@]:0:urlindex}") | ||
local url="${args[urlindex]}" | ||
|
||
curl -s -k -I $opts "$url" | head -n 1 | cut -d ' ' -f 2 | ||
curl -s -k -I "${opts[@]}" "$url" | head -n 1 | cut -d ' ' -f 2 | ||
} | ||
|
||
curl_get_status() { | ||
args=($@) | ||
urlindex=$[ ${#args[@]} - 1 ] | ||
opts="${args[@]:0:urlindex}" | ||
url="${args[urlindex]}" | ||
local args=("$@") | ||
local urlindex=$[ ${#args[@]} - 1 ] | ||
local opts=("${args[@]:0:urlindex}") | ||
local url="${args[urlindex]}" | ||
|
||
curl -s -k -i $opts "$url" | head -n 1 | cut -d ' ' -f 2 | ||
curl -s -k -i "${opts[@]}" "$url" | head -n 1 | cut -d ' ' -f 2 | ||
} | ||
|
||
curl_get_header() { | ||
args=($@) | ||
urlindex=$[ ${#args[@]} - 1 ] | ||
opts="${args[@]:0:urlindex}" | ||
url="${args[urlindex]}" | ||
local args=("$@") | ||
local urlindex=$[ ${#args[@]} - 1 ] | ||
local opts=("${args[@]:0:urlindex}") | ||
local url="${args[urlindex]}" | ||
|
||
curl -s -k -i $opts "$url" | sed -e '/^$/q' | ||
curl -s -k -i "${opts[@]}" "$url" | sed -e '/^$/q' | ||
} | ||
|
||
curl_get_body() { | ||
args=($@) | ||
urlindex=$[ ${#args[@]} - 1 ] | ||
opts="${args[@]:0:urlindex}" | ||
url="${args[urlindex]}" | ||
local args=("$@") | ||
local urlindex=$[ ${#args[@]} - 1 ] | ||
local opts=("${args[@]:0:urlindex}") | ||
local url="${args[urlindex]}" | ||
|
||
curl -s -k $opts "$url" | ||
curl -s -k "${opts[@]}" "$url" | ||
} | ||
|
||
curl_post_status() { | ||
curl_get_status -X POST "$@" | ||
} | ||
|
||
curl_upload_content() { | ||
url="$1" | ||
name="$2" | ||
value="$3" | ||
filename="$4" | ||
local url="$1" | ||
local name="$2" | ||
local value="$3" | ||
local filename="$4" | ||
curl -s -k -F "$name=$value;filename=$filename" "$url" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters