mirror of
https://github.com/httpie/cli.git
synced 2025-06-30 06:11:19 +02:00
Add the Snap build file for general Linux packaging
Based on the work of @elopio and @chipaca. - Added support for the `snapd` protocol URL. - Packaged Unix socket transport plugin.
This commit is contained in:
@ -57,7 +57,13 @@ $ port install httpie
|
||||
|
||||
### Linux
|
||||
|
||||
Most Linux distributions provide a package that can be installed using the
|
||||
HTTPie is available on the [Snap Store](https://snapcraft.io/httpie):
|
||||
|
||||
```bash
|
||||
$ snap install httpie
|
||||
```
|
||||
|
||||
And most Linux distributions provide a package that can be installed using the
|
||||
system package manager, for example:
|
||||
|
||||
```bash
|
||||
@ -351,12 +357,12 @@ There are a few different *request item* types that provide a convenient mechani
|
||||
|
||||
They are key/value pairs specified after the URL. All have in common that they become part of the actual request that is sent and that their type is distinguished only by the separator used: `:`, `=`, `:=`, `==`, `@`, `=@`, and `:=@`. The ones with an `@` expect a file path as value.
|
||||
|
||||
| Item Type | Description |
|
||||
| Item Type | Description |
|
||||
| -----------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| HTTP Headers `Name:Value` | Arbitrary HTTP header, e.g. `X-API-Token:123` |
|
||||
| URL parameters `name==value` | Appends the given name/value pair as a querystring parameter to the URL. The `==` separator is used. |
|
||||
| Data Fields `field=value`, `field=@file.txt` | Request data fields to be serialized as a JSON object (default), to be form-encoded (with `--form, -f`), or to be serialized as `multipart/form-data` (with `--multipart`) |
|
||||
| Raw JSON fields `field:=json` | Useful when sending JSON and one or more fields need to be a `Boolean`, `Number`, nested `Object`, or an `Array`, e.g., `meals:='["ham","spam"]'` or `pies:=[1,2,3]` (note the quotes) |
|
||||
| HTTP Headers `Name:Value` | Arbitrary HTTP header, e.g. `X-API-Token:123` |
|
||||
| URL parameters `name==value` | Appends the given name/value pair as a querystring parameter to the URL. The `==` separator is used. |
|
||||
| Data Fields `field=value`, `field=@file.txt` | Request data fields to be serialized as a JSON object (default), to be form-encoded (with `--form, -f`), or to be serialized as `multipart/form-data` (with `--multipart`) |
|
||||
| Raw JSON fields `field:=json` | Useful when sending JSON and one or more fields need to be a `Boolean`, `Number`, nested `Object`, or an `Array`, e.g., `meals:='["ham","spam"]'` or `pies:=[1,2,3]` (note the quotes) |
|
||||
| File upload fields `field@/dir/file`, `field@file;type=mime` | Only available with `--form`, `-f` and `--multipart`. For example `screenshot@~/Pictures/img.png`, or `'cv@cv.txt;type=text/markdown'`. With `--form`, the presence of a file field results in a `--multipart` request |
|
||||
|
||||
Note that the structured data fields aren’t the only way to specify request data:
|
||||
@ -411,10 +417,10 @@ Host: pie.dev
|
||||
|
||||
### Explicit JSON
|
||||
|
||||
You can use `--json, -j` to explicitly set `Accept` to `application/json` regardless of whether you are sending data (it’s a shortcut for setting the header via the usual header notation: `http url Accept:'application/json, */*;q=0.5'`).
|
||||
You can use `--json, -j` to explicitly set `Accept` to `application/json` regardless of whether you are sending data (it’s a shortcut for setting the header via the usual header notation: `http url Accept:'application/json, */*;q=0.5'`).
|
||||
Additionally, HTTPie will try to detect JSON responses even when the `Content-Type` is incorrectly `text/plain` or unknown.
|
||||
|
||||
### Non-string JSON fields
|
||||
### Non-string JSON fields
|
||||
|
||||
Non-string JSON fields use the `:=` separator, which allows you to embed arbitrary JSON data into the resulting JSON object.
|
||||
Additionally, text and raw JSON files can also be embedded into fields using `=@` and `:=@`:
|
||||
@ -717,9 +723,9 @@ the [sessions](#sessions) feature.
|
||||
$ http -a username pie.dev/basic-auth/username/password
|
||||
```
|
||||
|
||||
### Empty password
|
||||
### Empty password
|
||||
|
||||
```bash
|
||||
```bash
|
||||
$ http -a username: pie.dev/headers
|
||||
```
|
||||
|
||||
@ -927,13 +933,13 @@ By default, HTTPie only outputs the final response and the whole response
|
||||
Print request and response headers:
|
||||
|
||||
```bash
|
||||
$ http --print=Hh PUT pie.dev/put hello=world
|
||||
$ http --print=Hh PUT pie.dev/put hello=world
|
||||
```
|
||||
|
||||
### Verbose output
|
||||
### Verbose output
|
||||
|
||||
`--verbose` can often be useful for debugging the request and generating documentation examples:
|
||||
|
||||
`--verbose` can often be useful for debugging the request and generating documentation examples:
|
||||
|
||||
```bash
|
||||
$ http --verbose PUT pie.dev/put hello=world
|
||||
PUT /put HTTP/1.1
|
||||
@ -942,10 +948,10 @@ It accepts a string of characters each of which represents a specific part of th
|
||||
Content-Type: application/json
|
||||
Host: pie.dev
|
||||
User-Agent: HTTPie/0.2.7dev
|
||||
|
||||
{
|
||||
"hello": "world"
|
||||
}
|
||||
|
||||
{
|
||||
"hello": "world"
|
||||
}
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Connection: keep-alive
|
||||
@ -1162,13 +1168,13 @@ Syntax highlighting is applied to HTTP headers and bodies (where it makes sense)
|
||||
| `--pretty=format` | Apply formatting |
|
||||
| `--pretty=none` | Disables output processing. Default for redirected output |
|
||||
|
||||
You can further control the applied formatting via the more granular [format options](#format-options).
|
||||
You can further control the applied formatting via the more granular [format options](#format-options).
|
||||
|
||||
### Format options
|
||||
### Format options
|
||||
|
||||
The `--format-options=opt1:value,opt2:value` option allows you to control how the output should be formatted
|
||||
when formatting is applied. The following options are available:
|
||||
|
||||
when formatting is applied. The following options are available:
|
||||
|
||||
| Option | Default value | Shortcuts |
|
||||
| ---------------: | :-----------: | ------------------------ |
|
||||
| `headers.sort` | `true` | `--sorted`, `--unsorted` |
|
||||
@ -1178,12 +1184,12 @@ Also, the following formatting is applied:
|
||||
| `xml.format` | `true` | N/A |
|
||||
| `xml.indent` | `2` | N/A |
|
||||
|
||||
For example, this is how you would disable the default header and JSON key
|
||||
For example, this is how you would disable the default header and JSON key
|
||||
sorting, and specify a custom JSON indent size:
|
||||
|
||||
|
||||
```bash
|
||||
$ http --format-options headers.sort:false,json.sort_keys:false,json.indent:2 pie.dev/get
|
||||
```
|
||||
```
|
||||
|
||||
There are also two shortcuts that allow you to quickly disable and re-enable
|
||||
sorting-related format options (currently it means JSON keys and headers):
|
||||
@ -1192,14 +1198,14 @@ You can further control the applied formatting via the more granular [format opt
|
||||
This is something you will typically store as one of the default options in your [config](#config) file.
|
||||
|
||||
### Binary data
|
||||
|
||||
|
||||
Binary data is suppressed for terminal output, which makes it safe to perform requests to URLs that send back binary data.
|
||||
Binary data is also suppressed in redirected but prettified output.
|
||||
The connection is closed as soon as we know that the response body is binary,
|
||||
|
||||
```bash
|
||||
$ http pie.dev/bytes/2000
|
||||
```
|
||||
Binary data is also suppressed in redirected but prettified output.
|
||||
The connection is closed as soon as we know that the response body is binary,
|
||||
|
||||
```bash
|
||||
$ http pie.dev/bytes/2000
|
||||
```
|
||||
|
||||
You will nearly instantly see something like this:
|
||||
|
||||
|
108
snapcraft.yaml
Normal file
108
snapcraft.yaml
Normal file
@ -0,0 +1,108 @@
|
||||
name: httpie
|
||||
title: HTTPie
|
||||
summary: Modern, user-friendly command-line HTTP client for the API era
|
||||
description: |
|
||||
HTTPie *aitch-tee-tee-pie* is a user-friendly command-line HTTP client
|
||||
for the API era.
|
||||
It comes with JSON support, syntax highlighting, persistent sessions,
|
||||
wget-like downloads, plugins, and more.
|
||||
|
||||
The project's goal is to make CLI interaction with web services as
|
||||
human-friendly as possible. HTTPie is designed for testing, debugging,
|
||||
and generally interacting with APIs & HTTP servers.
|
||||
The http & https commands allow for creating and sending arbitrary HTTP
|
||||
requests. They use simple and natural syntax and provide formatted and
|
||||
colorized output.
|
||||
|
||||
Main features:
|
||||
- Built-in JSON support
|
||||
- Colorized and formatted terminal output
|
||||
- Sensible defaults for the API era
|
||||
- Persistent sessions
|
||||
- Forms and file uploads
|
||||
- HTTPS, proxies, and authentication support
|
||||
- Support for arbitrary request data and headers
|
||||
- Wget-like downloads
|
||||
- Extensions API
|
||||
- Expressive and intuitive syntax
|
||||
- Linux, macOS, and Windows support
|
||||
- All that & more in 2 simple commands: http + https
|
||||
|
||||
Links
|
||||
- Documentation: https://httpie.io/docs
|
||||
- Try in browser: https://httpie.io/run
|
||||
- GitHub: https://github.com/httpie/httpie
|
||||
- Twitter: https://twitter.com/httpie
|
||||
- Discord: https://httpie.io/chat
|
||||
license: BSD-3-Clause-LBNL
|
||||
|
||||
# Automatically change the current version based on the source code
|
||||
adopt-info: httpie
|
||||
|
||||
# https://snapcraft.io/docs/snapcraft-top-level-metadata#heading--icon
|
||||
# icon:
|
||||
|
||||
base: core20
|
||||
confinement: strict
|
||||
grade: stable
|
||||
|
||||
parts:
|
||||
httpie:
|
||||
source: .
|
||||
plugin: python
|
||||
|
||||
# Guess the current version from sources
|
||||
override-pull: |
|
||||
snapcraftctl pull
|
||||
snapcraftctl set-version $(grep '__version__' httpie/__init__.py | cut -d"'" -f2)
|
||||
|
||||
override-build: |
|
||||
snapcraftctl build
|
||||
|
||||
echo "Adding HTTPie plugins ..."
|
||||
python -m pip install httpie-unixsocket
|
||||
python -m pip install httpie-snapdsocket
|
||||
|
||||
echo "Removing no more needed modules ..."
|
||||
python -m pip uninstall -y pip wheel
|
||||
|
||||
override-prime: |
|
||||
snapcraftctl prime
|
||||
|
||||
echo "Removing useless files ..."
|
||||
packages=$SNAPCRAFT_PRIME/lib/python3.8/site-packages
|
||||
rm -rfv $packages/_distutils_hack
|
||||
rm -rfv $packages/pkg_resources/tests
|
||||
rm -rfv $packages/requests_unixsocket/test*
|
||||
rm -rfv $packages/setuptools
|
||||
|
||||
echo "Compiling pyc files ..."
|
||||
python -m compileall -f $packages
|
||||
|
||||
echo "Copying extra files ..."
|
||||
cp $SNAPCRAFT_PART_SRC/extras/httpie-completion.bash $SNAPCRAFT_PRIME/bin/
|
||||
|
||||
plugs:
|
||||
dot-config-httpie:
|
||||
interface: personal-files
|
||||
write:
|
||||
- $HOME/.config/httpie
|
||||
|
||||
apps:
|
||||
http:
|
||||
command: bin/http
|
||||
plugs: &plugs
|
||||
- dot-config-httpie
|
||||
- home
|
||||
- network
|
||||
- removable-media
|
||||
completer: bin/httpie-completion.bash
|
||||
environment:
|
||||
LC_ALL: C.UTF-8
|
||||
|
||||
https:
|
||||
command: bin/https
|
||||
plugs: *plugs
|
||||
completer: bin/httpie-completion.bash
|
||||
environment:
|
||||
LC_ALL: C.UTF-8
|
Reference in New Issue
Block a user