docs: Added CLI usage instructions

This commit is contained in:
Sayantan Santra 2024-03-31 21:07:31 -05:00
parent d48b664c0a
commit a9168e3459
Signed by: SinTan1729
GPG Key ID: EB3E68BFBA25C85F
1 changed files with 32 additions and 0 deletions

View File

@ -122,6 +122,38 @@ default, the auto-generated links are adjective-name pairs. You can use UIDs by
the `slug_style` variable to `UID`. You can also set the length of those slug by setting
the `slug_length` variable. It defaults to 8, and a minimum of 4 is supported.
## CLI usage instructions
The application can be used from the terminal using something like `curl`. In all the examples
below, replace `http://localhost:4567` with where your instance of `chhoto-url` is accessible.
If you have set up
a password, first do the following to get an authentication cookie and store it in a file.
```bash
curl -X post -d "<your-password>" -c cookie.txt http://localhost:4567/api/login
```
You should receive "Correct password!" in case the provided password was correct. For any other
request, please add `-b cookie.txt` to use this authentication cookie.
To add a link, do
```bash
curl -X POST -d '{"shhortlink":"<shortlink>", "longlink":<longlink>}' http://localhost:4567/api/new
```
Send an empty `<shortlink>` if you want it to be auto-generated. The server will reply with the generated shortlink.
To get a list of all the currently available links as `json`, do
```bash
curl http://localhost:4567/api/all
```
To delete a link, do
```bash
curl -X DELETE http://localhost:4567/api/del/<shortlink>
```
The server will send a confirmation.
You can get the version of `chhoto-url` the server is running using `curl http://localhost:4567/api/version` and
get the siteurl using `curl http://localhost:4567/api/siteurl`.
## Disable authentication
If you do not define a password environment variable when starting the docker image, authentication
will be disabled.