Command line interface
Posted 2023-02-05 23:25. Tagged web, rust, project.
I wrote a little command-line interface for sending a http request and
getting the response.
I call the package url-cli, and the command itself is
It has sub-commands for the different http methods.
If you have a rust toolchain installed, you can get it by cargo install. I haven’t made any binary packages yet.
Yes, I know that
curl exists and is generally
great, along with lots of others, like
Still, last Thursday I got a bit annoyed at the existing commands and
decided to roll my own small cli around the excellent rust http crate
This tool is still young, initial version is just released, but the release notes show that it supports pretty much all I need at the moment:
- Support GET, HEAD, PATCH, POST, PUT, and DELETE requests.
- Writes response body to stdout.
- Arguments for generic headers, bearer authentication, request body and content type.
--verboseflag to show request and response headers on stderr.
There is no code involved for paging or formatting the body, it is just written as-is to standard output. Pipe it to bat for code highlighting and paging, to jq for json querying and formatting, cli-selector for getting elements (or their contents or attributes) identified by css selectors, or your favorite tools for the format you’re working with.
The code is on https://codeberg.org/rkaj/url-cli. Go there and take a look at the code, report an issue if something is missing. Maybe even write some changes and submit a pull request?
Wait, what? Codeberg?
Yes. Lots of my code are on github. Probably lots of yours too, if you write code. I find it rather ironic that nearly all open source code are hosted on a single closed-source service provided by one single company.
So when I heard about Codeberg about a month ago, I decided I should try it out. The service is provided by Codeberg e.V, a registered non-profit association based in Berlin, Germany. It is possible to join the association to support it, but the service is free and open to non-members as well as members.
The service itself is the forgejo (which used to be known as gitea until gitea was incorporated as a for-profit company).