soil-schema / soil

REST api schema and code generator
MIT License
1 stars 0 forks source link

Add concept: Request Body Source #56

Open niaeashes opened 2 years ago

niaeashes commented 2 years ago

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.

How supports multipart/form-data?

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.