Form
jin-frame supports form data submission, which can be handled in two main ways:
application/x-www-form-urlencodedmultipart/form-data
These formats make it easy to handle file uploads or form field submissions.
application/x-www-form-urlencoded
The application/x-www-form-urlencoded format serializes form fields into URL-encoded key-value pairs using the native URLSearchParams API. Set the contentType option to application/x-www-form-urlencoded and annotate each field with @Body().
@Post({
host: 'http://some.api.google.com/jinframe/:passing',
contentType: 'application/x-www-form-urlencoded',
})
class TestUrlencodedPostFrame extends JinFrame {
@Param()
declare public readonly passing: string;
@Body()
declare public readonly username: string;
@Body()
declare public readonly password: string;
}jin-frame encodes all @Body() fields into application/x-www-form-urlencoded format automatically — no extra configuration needed.
multipart/form-data
The multipart/form-data format is mainly used for file uploads or complex data submissions. jin-frame uses the native FormData API to build the request body. Use JinFile to wrap file data and annotate fields with @Body().
Supported HTTP methods: POST, PUT, PATCH.
@Post({
host: 'http://some.api.google.com/fileupload-case04',
contentType: 'multipart/form-data',
})
class UploadFrame extends JinFrame {
@Body()
declare public readonly description: string;
@Body()
declare public readonly myFile: JinFile<Buffer>;
@Body()
declare public readonly myFiles: JinFile<Buffer>[];
}- When
contentTypeis set tomultipart/form-data, jin-frame uses the nativeFormDataAPI to build the request body automatically. - The
Content-Typeheader (including the multipart boundary) is set by the runtime — do not set it manually.
This makes it simple to upload a variety of data types, including images, documents, and binary files.
Summary
- Use
application/x-www-form-urlencodedfor simple key-value data submissions. - Use
multipart/form-datawhen uploading files or sending complex structured data.