Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: edit page #13507

Merged
merged 13 commits into from
Aug 25, 2024
36 changes: 20 additions & 16 deletions pages/common/http.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# http

> HTTPie: HTTP client, aims to be easier to use than cURL.
> More information: <https://httpie.org>.
> HTTPie: an HTTP client designed for testing, debugging, and generally interacting with APIs & HTTP servers.
> More information: <https://httpie.io/docs/cli/usage>.

- Download a URL to a file:
- Make a simple GET request (shows response header and content):

`http --download {{example.org}}`
`http {{https://example.org}}`

- Send form-encoded data:
- Print specific output content (`H`: request headers, `B`: request body, `h`: response headers, `b`: response body, `m`: response metadata):
spageektti marked this conversation as resolved.
Show resolved Hide resolved

`http --form {{example.org}} {{name='bob'}} {{profile_picture@'bob.png'}}`
`http --print {{H|B|h|b|m|Hh|Hhb|...}} {{https://example.com}}`

- Send JSON object:
- Specify the HTTP method when sending a request:

`http {{example.org}} {{name='bob'}}`
`http {{GET|POST|HEAD|PUT|PATCH|DELETE|...}} {{https://example.com}}`

- Specify an HTTP method:
- Follow any `3xx` redirects and specify additional headers in a request:

`http {{HEAD}} {{example.org}}`
`http {{--follow|-F}} {{https://example.com}} {{'User-Agent: Mozilla/5.0' 'Accept-Encoding: gzip'}}`

- Include an extra header:
- Authenticate to a server using different authentication methods:

`http {{example.org}} {{X-MyHeader:123}}`
`http --auth {{username:password|token}} --auth-type {{basic|digest|bearer}} {{GET|POST|...}} {{https://example.com/auth}}`

- Pass a username and password for server authentication:
- Construct a request but do not send it (similar to a dry-run):

`http --auth {{username:password}} {{example.org}}`
`http --offline {{GET|DELETE|...}} {{https://example.com}}`

- Specify raw request body via `stdin`:
- Use named sessions for persistent custom headers, auth credentials and cookies:

`cat {{data.txt}} | http PUT {{example.org}}`
`http --session {{session_name|path/to/session.json}} {{--auth username:password https://example.com/auth API-KEY:xxx}}`

- Upload a file to a form (the example below assumes form field is `<input type="file" name="cv" />`):

`http --form {{POST}} {{https://example.com/upload}} {{cv@path/to/file}}`