libcurl is used by tons and tons of software and products that need to communicate over a network. Everything from webapps to video games to network devices to cars to TVs. See this <em>very</em> incomplete list.. I work for a company on the list and we use cURL all over the damn place! Although some of us are converting over to HTTPie for CLI and Requests for library usage, there are many places where cURL remains the best option.
Header name should be 'X-CSRFToken' with value taken out of 'csrftoken' cookie. I think you need to create session with httpie, so it will preserve cookie. Read https://httpie.org/doc to see how you can achive that.
Btw. Are you using DRF to create API? It's very useful.
It looks like .http
files are only mentioned in one spot in the docs: https://httpie.org/docs/2.2.0#offline-mode
It looks like httpie can use the --offline
flag to produce a .http
file kind of output (which can be stored via redirect).
Maybe this means you can use an .http
file as input (by redirecting into httpie) and it'll just work? I'm not sure, just guessing, but it seems likely enough given that the output is shown in that use case.
I don't think this tool is really designed to be better than cURL, so much as more pleasant to use than cURL. The syntax is more fluent. The named sessions feature also looks helpful.
I am using my cli api wrapper, which means you need to set up fish shell and httpie if you want to copy and paste the code, but it maps to the standard API transparently. I'd also recommend jq if you ever touch JSON on the command line.
Getting a list of all podcasts:
airsonic -u $user -p $pass getPodcasts includeEpisodes==1
Filtering for downloaded (and therefore streamable episodes):
airsonic -u $user -p $pass getPodcasts includeEpisodes==1 | jq '.["subsonic-response"].podcasts.channel[].episode[] | select(.status == "completed")'
Initiating an episode download works like this:
airsonic -u $user -p $pass downloadPodcastEpisode id==$id
You can get the correct id
parameter from the getPodcasts
response above.
Each episode has a property streamId
, which you can use to stream it:
airsonic -u $user -p $pass stream id==$streamId
So putting it togehter:
# select random podcast episode
episode=$(airsonic -u $user -p $pass getPodcasts includeEpisodes==1 | jq -c '.["subsonic-response"].podcasts.channel[].episode[] | select(.status == "completed")' | shuf -n 1)
# play episode
airsonic -u $user -p $pass stream $(echo $episode | jq '.streamId') | play
Where play
would be the command you use to play the actual audio file. Hope this helps!
It's a CLI HTTP client https://httpie.org/docs
GET
$ http localhost:8080/api/posts/
POST with credentials
$ http -a onosendi:mypass localhost:8080/api/posts/ body='Hey this is my post!'
GET with token
$ http localhost:8080/api/posts/ "Authentication: Bearer token-here"
curl is installable on windows. Use that and call the REST API on HA.
If you already have python installed, I like httpie: https://httpie.org/
There's also hass-cli: https://github.com/home-assistant/home-assistant-cli
I haven't used it though.
Not really helping with storing and re-using requests but I think HTTPie has a much more user friendly interface compared to curl. I know curl supports this as well but you can store and re-use request bodies in files. Give it a try!
From requests documentation:
>>> url = 'https://api.github.com/some/endpoint'
>>> payload = {'some': 'data'}
>>> r = requests.post(url, json=payload)
It automatically econdes as json when you pass the data through the json
keyword argument.
Also, you recommend https://httpie.org/ for making api requests from the command line, it's easier to deal with json content than using curl
.
http PUT http://localhost:8000/..../lights/5/state on=false
I also don't know how to represent "read looking for --data-binary "@/usr/bin/curl"
" in snark, but suffice to say I didn't see any such thing was possible with httpie, either, to say nothing of how many hundreds of docker images contain curl
versus the number that contain httpie
I use <code>fasd</code> which replaces both z
(which I used previously) and fzf
.
Some other good ones, especially for web stuff:
<code>jq</code>: json parsing/coloring/query language
<code>httpie</code>: curl + jq
Sure, in a perfect world everything runs in a container. But much of the time that's not the case, especially when you're talking about little command-line tools (I'm not going to launch a new container every time I want to run http, for instance).
For most companies, it is absolutely not worth taking on the maintenance burden of compiling their own version of Python; the distro will do it better and faster than you.