danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
900 stars 74 forks source link

Question: Is it possible to send multipart/form-data request? #218

Open Klarys opened 1 year ago

Klarys commented 1 year ago

Hello! I'm working with an API that requires me to send some files as multipart/form-data. Is this possible to achieve with restish? This is how the command's help looks like:

  ## Argument Schema:                                                                                                                                                                                                              

    {                                                                                                                                                                                                                              
      id: (string)                                                                                                                                                                                                         
    }                                                                                                                                                                                                                              

  ## Input Example                                                                                                                                                                                                                 

    {                                                                                                                                                                                                                              
      "filename": [                                                                                                                                                                                                                
        "string"                                                                                                                                                                                                                   
      ]                                                                                                                                                                                                                            
    }                                                                                                                                                                                                                              

  ## Request Schema (multipart/form-data)                                                                                                                                                                                          

    {                                                                                                                                                                                                                              
      filename: [                                                                                                                                                                                                                  
        (string format:binary)                                                                                                                                                                                                     
      ]                                                                                                                                                                                                                            
    } 

I've tried several approaches but I wasn't able to figure out something that works. Some examples: 1.

restish my-api upload-file 650d9c463c92333e6aa6cc0 @file
ERROR: Caught error: not sure how to marshal multipart/form-data

2.

restish my-api upload-file 650d9c463c92333e6aa6cc0 filename: @file
ERROR: Caught error: not sure how to marshal multipart/form-data

I've also tried adding -H "Content-Type: multipart/form-data" to those commands but the result was the same. Am I doing something wrong or is there just no support for multipart/form-data? I will really appreciate any help, thanks!

danielgtaylor commented 1 year ago

@Klarys there's no special logic to handle multi-part forms in Restish yet. For now you can use curl to do it, e.g. see https://everything.curl.dev/http/multipart. I'll consider this a feature request to support it in Restish and will see what I can do.

Klarys commented 1 year ago

Thank you for answering and considering this as a future feature request. This functionality is crucial for my use case, so it would be really great to see it implemented.