eykrehbein / strest

⚡️ CI-ready tests for REST APIs configured in YAML
MIT License
1.74k stars 59 forks source link

Added support for sending form data #141

Closed shrikster closed 5 years ago

shrikster commented 5 years ago

7 #23

I Added support for sending form data including files . that uses the params property inside the postData when the mimeType is application/x-www-form-urlencoded all the param All the params are passed as a simple url params in the body param1=value1& param2=value2 when the mimeType is multipart/form-data the name value pair are being converted to a FormData object that also can contains files. I added a custom nunjuck filter called file. it's just convert the file to his actual path , and prefix it with the string sendFile: this is passed to the postData as a file steam .

jgroom33 commented 5 years ago

the HAR spec looks a little different than what is implemented here.

Do you think there's a way to implement it closer to the spec?

"params": [
    {
        "name": "paramName",
        "value": "paramValue",
        "fileName": "example.pdf",
        "contentType": "application/pdf",
        "comment": ""
    }
]

List of posted parameters, if any (embedded in object).

name [string] - name of a posted parameter. value [string, optional] - value of a posted parameter or content of a posted file. fileName [string, optional] - name of a posted file. contentType [string, optional] - content type of a posted file. comment [string, optional] (new in 1.2) - A comment provided by the user or the application.

shrikster commented 5 years ago

Sure NP i was debating that issue with myself as well ...

shrikster commented 5 years ago

the HAR spec looks a little different than what is implemented here.

I tried my best to be as close to the HAR format as i can. (changed it from form to params) regarding the files - I can't find an example on how will multiple files will be sent .. @jgroom33 maybe you have an example for HAR with multiple files ?

jgroom33 commented 5 years ago

Does the example file.strest.yml work as you expect?

Another option is to use contentType to trigger the file upload. This would eliminate the custom jinja filter.

But, I like the jinja filter approach also. The jinja filter approach avoids handling various contentTypes.

"params": [
    {
        "name": "paramName",
        "value": "..path.to.file",
        "fileName": "example.pdf",
        "contentType": "application/pdf"
    },
    {
        "name": "paramName",
        "value": "..path.to.file",
        "fileName": "example.pdf",
        "contentType": "application/pdf",
        "comment": ""
    }
]
yaominator commented 5 years ago

any ETA to merge this. This is a really useful patch.

yaominator commented 5 years ago

this tool is awesome, but missing the file upload is a pity.