base on š Parses and serializes multipart-encoded data with Codable support. <p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/multipart-kit/assets/1130717/4b3aed4e-2b18-4689-80c8-d31ccf169947">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/multipart-kit/assets/1130717/5c60750b-ef11-4137-9f9e-917ebcc49ca6">
<img src="https://github.com/vapor/multipart-kit/assets/1130717/5c60750b-ef11-4137-9f9e-917ebcc49ca6" height="96" alt="MultipartKit">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/multipart-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/multipart-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/multipart-kit"><img src="https://img.shields.io/codecov/c/github/vapor/multipart-kit?style=plastic&logo=codecov&label=Codecov&token=yDzzHja8lt"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
</p>
š Multipart parser and serializer with `Codable` support for Multipart Form Data.
### Installation
Use the SPM string to easily include the dependency in your `Package.swift` file.
Add MultipartKit to your package dependencies:
```swift
dependencies: [
// ...
.package(url: "https://github.com/vapor/multipart-kit.git", from: "4.0.0"),
]
```
Add MultipartKit to your target's dependencies:
```swift
targets: [
.target(name: "MyAppTarget", dependencies: [
// ...
.product(name: "MultipartKit", package: "multipart-kit"),
])
]
```
### Supported Platforms
MultipartKit supports the following platforms:
- All Linux distributions supported by Swift 5.7+
- macOS 10.15+
## Overview
MultipartKit is a multipart parsing and serializing library. It provides `Codable` support for the special case of the `multipart/form-data` media type through a `FormDataEncoder` and `FormDataDecoder`. The parser delivers its output as it is parsed through callbacks suitable for streaming.
### Multipart Form Data
Let's define a `Codable` type and a choose a boundary used to separate the multipart parts.
```swift
struct User: Codable {
let name: String
let email: String
}
let user = User(name: "Ed", email: "
[email protected]")
let boundary = "abc123"
```
We can encode this instance of a our type using a `FormDataEncoder`.
```swift
let encoded = try FormDataEncoder().encode(foo, boundary: boundary)
```
The output looks then looks like this.
```
--abc123
Content-Disposition: form-data; name="name"
Ed
--abc123
Content-Disposition: form-data; name="email"
[email protected]
--abc123--
```
In order to _decode_ this message we feed this output and the same boundary to a `FormDataDecoder` and we get back an identical instance to the one we started with.
```swift
let decoded = try FormDataDecoder().decode(User.self, from: encoded, boundary: boundary)
```
### A note on `null`
As there is no standard defined for how to represent `null` in Multipart (unlike, for instance, JSON), FormDataEncoder and FormDataDecoder do not support encoding or decoding `null` respectively.
### Nesting and Collections
Nested structures can be represented by naming the parts such that they describe a path using square brackets to denote contained properties or elements in a collection. The following example shows what that looks like in practice.
```swift
struct Nested: Encodable {
let tag: String
let flag: Bool
let nested: [Nested]
}
let boundary = "abc123"
let nested = Nested(tag: "a", flag: true, nested: [Nested(tag: "b", flag: false, nested: [])])
let encoded = try FormDataEncoder().encode(nested, boundary: boundary)
```
This results in the content below.
```
--abc123
Content-Disposition: form-data; name="tag"
a
--abc123
Content-Disposition: form-data; name="flag"
true
--abc123
Content-Disposition: form-data; name="nested[0][tag]"
b
--abc123
Content-Disposition: form-data; name="nested[0][flag]"
false
--abc123--
```
Note that the array elements always include the index (as opposed to just `[]`) in order to support complex nesting.
", Assign "at most 3 tags" to the expected json: {"id":"11008","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"