Skip to main content
Version: Next 🚧

Multipart

This doc details what emitters will generate for multipart request.

Common multipart request​

When content-type of operation is "multipart/form-data", the body payload is multipart payload.

model Address {
city: string;
}
model MultipartRequest {
id: string;
address: Address;
profileImage: bytes;
pictures: bytes[];
}

@post
op upload(
@header contentType: "multipart/form-data",
@body body: MultipartRequest,
): NoContentResponse;

Multipart request with @multipartBody​

With @multipartBody, typespec author could define part of multipart request with more detailed info. For example, typespec author could use File model predefined in @typespec/http to declare the requiredness of filename and contentType.

model Address {
city: string;
}
model MultipartRequest {
id: HttpPart<string>;
address: HttpPart<Address>;
profileImage: HttpPart<File>;
previousAddresses: HttpPart<Address[]>;
pictures: HttpPart<File>[];
}

@post
op upload(
@header contentType: "multipart/form-data",
@multipartBody body: MultipartRequest,
): NoContentResponse;