curl is great, but I do find myself reaching for httpie to simplify header manipulation and JSON handling.
For example, I’m tinkering with the World History Gazetteer API and the JSON payload can get pretty big and indented.
httpie’s http command makes this relatively easy with a structure that is a lot easier to script.
Here’s my shell script:
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
TOKEN=MY_SECRET_TOKEN
http --verbose POST https://whgazetteer.org/reconcile/ \
-A bearer -a $TOKEN\
User-Agent:AlwaysMap \
queries[q1][query]='Denver'\
queries[q1][mode]=fuzzy \
queries[q1][fclasses][]=A \
queries[q1][fclasses][]=P \
queries[q1][countries][]=GB \
queries[q1][countries][]=US
That describes the structure of the JSON payload pretty well, including the arrays like countries and fclasses.
And here’s the payload, minus the massive response: