Easy command-line JSON posts
When I need to test API calls I’ll write a tiny shellscript that: 1. Takes some commandline arguments 2. Then performs an HTTP request with cURL
This is fine for simple things, but editing it is a pain and it gets messy fast. You’ll forget to escape quotes, and it will result in invalid JSON.
You could put your json into a separate file and then use cURL’s [--data-binary @file.json feature](https://ec.haxx.se/http-post.html). But then you lose the ability to weave commandline variables through your JSON.
What I find easiest is to keep everything in 1 script by using a feature called “Here Documents”.
<<EOF notation, you don’t have to escape any quotes, and you can still use $variables.
It works from the terminal too, handy when you need to do multi-line user-input. Give it a try:
P.S. I know there’s things like Postman but this is a lot more portable, and integrates well into ci pipelines.