Hey folks,
So, I was trying to figure out how to curl send json in a POST request, and man, it took me a hot minute to get it right. Like, why is it so confusing at first glance? Anyway, here's the deal:
You gotta use the `-H` flag to set the Content-Type to `application/json`, and then slap your JSON data in with `-d`. Something like this:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://example.com/api
```
But here’s the kicker—if your JSON is in a file, you can just do `-d @filename.json` instead of typing it all out. Lifesaver, honestly.
Also, pro tip: if you mess up the quotes or brackets, curl will just silently fail. So double-check that JSON, folks.
Anyway, hope this helps someone avoid the headache I went through. Cheers! 🍻
So, I was trying to figure out how to curl send json in a POST request, and man, it took me a hot minute to get it right. Like, why is it so confusing at first glance? Anyway, here's the deal:
You gotta use the `-H` flag to set the Content-Type to `application/json`, and then slap your JSON data in with `-d`. Something like this:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://example.com/api
```
But here’s the kicker—if your JSON is in a file, you can just do `-d @filename.json` instead of typing it all out. Lifesaver, honestly.
Also, pro tip: if you mess up the quotes or brackets, curl will just silently fail. So double-check that JSON, folks.
Anyway, hope this helps someone avoid the headache I went through. Cheers! 🍻
