The request variable holds the body, so the actual processing will change depending on it. For example, if the request starts with "file://", the content of the file is loaded and used as the HTTP Request Body. In the case of an Object, it is converted to a JSON string and sent.
Solution
RequestBodySource is working as a processing switcher likes adapter pattern.
ObjectRequestBodySource: Provide request body object will convert to a JSON string.
UrlRequestBodySource: It has a url and get request body from its url.
UnsplashRequestBodySource: Formatted string likes "unsplash:{Query}", it get request body from https://unsplash.com with api access key on core.unsplash config.
How supports multipart/form-data?
RequestBodySource.contentType: Expected Content-Type for HTTP Request. It this value is multipart/form-data in ObjectRequestBodySource, provided object is converted to multipart/form-data format data. If request body source don't support the content type, the soil scenario runner throw ScenarioRuntimeError .
Object Request Body Source
name
description
default
value
Simple JavaScript object.
required
Form Data Request Body Source
FormDataRequestBodySource has dynamic named parameter with static value or another request body source. It has image parameter has unsplash request body source instance, makes the form-data part named image body image binary data.
Parameter value is object, parse JSON and use application/json content-type. (don't support mixin data-form)
Url Request Body Source
name
description
default
url
Any url
required
contentType
supports all, but assert content-type on response header from the url. If this contentType is null, skip assertion.
null
Unsplash Request Body Source
name
description
default
query
Any string
required
Image from unsplash.com api.
Use as multipart/form-data, set unsplash request body source as a property of form data request body source.
Problem
The request variable holds the body, so the actual processing will change depending on it. For example, if the request starts with
"file://"
, the content of the file is loaded and used as the HTTP Request Body. In the case of an Object, it is converted to a JSON string and sent.Solution
RequestBodySource
is working as a processing switcher likes adapter pattern.ObjectRequestBodySource
: Provide request body object will convert to a JSON string.UrlRequestBodySource
: It has a url and get request body from its url.UnsplashRequestBodySource
: Formatted string likes"unsplash:{Query}"
, it get request body from https://unsplash.com with api access key oncore.unsplash
config.How supports
multipart/form-data
?RequestBodySource.contentType
: Expected Content-Type for HTTP Request. It this value ismultipart/form-data
inObjectRequestBodySource
, provided object is converted tomultipart/form-data
format data. If request body source don't support the content type, the soil scenario runner throwScenarioRuntimeError
.Object Request Body Source
Form Data Request Body Source
FormDataRequestBodySource has dynamic named parameter with static value or another request body source. It has
image
parameter has unsplash request body source instance, makes the form-data part namedimage
body image binary data.Parameter value is object, parse JSON and use
application/json
content-type. (don't support mixin data-form)Url Request Body Source
null
Unsplash Request Body Source
Image from unsplash.com api.