4 ms·
A while back I was trying to craft a curl request and in middle of it i made a mistake and started the command with GET. And it worked! For a moment I thought i
by emilsedgh 10y ago
A while back I was trying to craft a curl request and in middle of it i made a mistake and started the command with GET. And it worked! For a moment I thought its a Fish feature.
It turns out libwww-perl has commands named like HTTP methods installed in my /usr/bin.
So `GET http://foo` http://foo` works. Which is super convenient! Give it a try!
edit: There's a high chance its already installed on your machine.
- jkbr 10y agoThis tool has a really nice UI by which HTTPie is actually partly inspired. And it also includes `POST': $ echo 'hello=world' | POST httpbin.org/post
- xaduha 10y agoCan also be solved with some aliases to curl alias GET='curl -sk' alias DELETE='curl -sk -X DELETE' alias PUT='curl -sk -X PUT --data-binary @-' alias POST='curl -sk -X POST --data-binary @-' echo "hello" | POST localhost
- xaduha 10y agoprobably doesn't need that -k flag, I was just using it to test HTTPS server with a self-signed certificate
- ta0967 10y agodo not use -X without having read the manual, it can break redirects and other things. from the curl(1) manpage: -X, --request <command> (...) Normally you don't need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options. This option only changes the actual word used in the HTTP request, it does not alter the way curl behaves. So for example if you want to make a proper HEAD request, using -X HEAD will not suffice. You need to use the -I, --head option. The method string you set with -X will be used for all requests, which if you for example use -L, --location may cause unintended side-effects when curl doesn't change request method according to the HTTP 30x response codes - and similar. PUT is indicated by using -T / --upload-file, POST by -d / --data or any --data-foo option (eg. --data-raw). DELETE is the only HTTP method in the parent list that needs -X to be used.
- xaduha 10y agoThe point is to have the ability to pipe to curl, will -T / --upload-file allow that? For now I'm happy with how it worked.
- ta0967 10y agothe manpage is very explicit about that: Use the file name "-" (a single dash) to use stdin instead of a given file. Alternately, the file name "." (a single period) may be specified instead of "-" to use stdin in non-blocking mode to allow reading server output while stdin is being uploaded.