xh icon indicating copy to clipboard operation
xh copied to clipboard

Consider supporting reading http request from a file

Open ducaale opened this issue 7 months ago • 2 comments

See https://github.com/httpie/cli/issues/537#issuecomment-264718507

This helps with editing complex requests in an editor and allows them to be easily reused (similar to how collections are used in other tools).

Example:

Generate and save a request using --offline:

$ xhs jsonplaceholder.typicode.com/posts title=foo body=bar userId:=1 --offline > add-todo.http

Modify the request file (e.g remove some headers and add templated Authorization header):

POST /posts HTTP/1.1
Accept: application/json, */*;q=0.5
Authorization: Bearer {{ ACCESS_TOKEN }}
Content-Type: application/json
Host: jsonplaceholder.typicode.com

{
    "title": "foo",
    "body": "bar",
    "userId": 1
}

Replay the request later using --http-file:

$ ACCESS_TOKEN=super-secret-token xhs --body --http-file add-todo.http 
{
    "title": "foo",
    "body": "bar",
    "userId": 1,
    "id": 101
}

Edit: Actually, there is no need for templating if users can override request from cli e.g

$ xhs --body --http-file=add-todo.http 'authorization:Bearer super-secret-token'
{
    "title": "foo",
    "body": "bar",
    "userId": 1,
    "id": 101
}

ducaale avatar Apr 25 '25 11:04 ducaale

cURL has https://github.com/curl/h2c for converting HTTP requests to a curl command

ducaale avatar Apr 27 '25 21:04 ducaale

This plugin is very useful for VS Code users. xh is also supported.

https://github.com/wk-j/vscode-httpie

Image

zuisong avatar May 06 '25 07:05 zuisong