Skip to content

url commands: inconsistencies and missing features #14162

@Bahex

Description

@Bahex

Related problem

  • There is no built-in counterpart to url build-query for splitting a query string (though this is not hard to implement in nushell)

  • url join's handling of parameters don't match url build-query, specifically it doesn't support lists

  • url parse can create records with duplicate keys

    > "http://host?a=1&b=2&b=3" | url parse | get params
    ╭───┬───╮
     a  1 
     b  2 
     b  3 
    ╰───┴───╯

Describe the solution you'd like

  • provide url split-query either as a built-in or as a std function

    def "url split-query" []: [string -> table<key: string, value: string>] {
      split row '&'
      | split column '=' -n 2 key value
      | update cells { url decode }
    }
  • url join and url build-query should use a common implementation.

  • url parse's params should either:

    • group the same keys into a list.
    • instead of a record, be a key-value table. (table<key: string, value: string>)

    second option seems preferable as it would preserve order of parameters, which might carry meaning in different APIs

  • if url parse | get params returns a table<key:string, value:string>, url join should also support the same in its input.

Describe alternatives you've considered

No response

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:networkingAll about our `http` and `url` commands and everything going accross the network.category:enhancementNew feature or requeststatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions