talis-fb / TReq

A CLI tool for effortless HTTP requests
GNU General Public License v3.0
55 stars 2 forks source link

Add file based operator `@` to insert value from files to request items #23

Open talis-fb opened 8 months ago

talis-fb commented 8 months ago

The objective is to replicate this feature in HTTPie (https://httpie.io/docs/cli/file-based-separators).

The goal it is: instead of using a static string as the value for some header, you can use :@ operator to pass the desired value from a file. Example, let's suppose I cd in a folder with a data.json file with content { "email": "...", "password": "..." } and a file "name.txt" with content as just Thales. You'll can...

treq POST httpbin.org/post \
    name=@name.txt               # Read a data field’s value from a file
    datas:=@data.json        # Embed a JSON object from a file
    X-Data:@files/another-file.txt             # Read a header from a file
    token==@files/token.txt             # Read a query parameter from a file

Additional Considerations:

This handler should live in input parsers to request data.

It must exist a function to receive input of "file path" and reader it, returning the String of content. This function would be called inside functions of parsers_request_items (that should pass to it the value they extracted from their input).