talis-fb / TReq

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

Alias for simplifying localhost URLs with `:PORT/` instead `localhost:PORT/` #3

Closed talis-fb closed 8 months ago

talis-fb commented 9 months ago

The objective is to replicate the convenient localhost URL shortcut feature found in HTTPie (https://httpie.io/docs/cli/url-shortcuts-for-localhost). The proposal suggests introducing an alias of the form :PORT/ to streamline localhost URLs.

Instead of requiring users to type treq GET localhost:3000/route, they can now use the shorthand treq GET :3000/route.

Expected Behavior:

Possible Solution/Implementation

Currently the Url is stored as a single String. In RequestData entity. To facilitate the implementation of this and potential future solutions, it is recommended to replace this single string with a struct that comprehensively stores all URL information.

Url<'a> {
    protocol: Option<&str>, // The default would be "http"
    host: &str,
    port: Option<u16>,
    path: &str,
    query_params: Vec<(&str, &str)>,
    anchor: Option<&str>,
},

This struct should include a function (returning a Result) to parse a string into it, validating if the parameter can be constructed from this struct. This enhancement will not only accommodate the proposed alias feature but also opens the door for additional URL aliases in the future.