• Stars
    star
    124
  • Rank 278,959 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿž Parses and serializes multipart-encoded data with Codable support.

Multipart

Documentation Team Chat MIT License Continuous Integration Swift 5.4 Twitter

๐Ÿž Multipart parser and serializer with Codable support for Multipart Form Data.

Major Releases

The table below shows a list of MultipartKit major releases alongside their compatible NIO and Swift versions.

Version NIO Swift SPM
4.0 2.2 5.4+ from: "4.0.0"
3.0 1.0 4.0+ from: "3.0.0"
2.0 N/A 3.1+ from: "2.0.0"
1.0 N/A 3.1+ from: "1.0.0"

Use the SPM string to easily include the dependency in your Package.swift file.

.package(url: "https://github.com/vapor/multipart-kit.git", from: ...)

Supported Platforms

MultipartKit supports the following platforms:

  • All Linux distributions supported by Swift
  • 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.

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.

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.

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.

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.

More Repositories

1

vapor

๐Ÿ’ง A server-side Swift HTTP web framework.
Swift
23,650
star
2

fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
Swift
1,271
star
3

redis

Vapor provider for RediStack
Swift
462
star
4

console-kit

๐Ÿ’ป APIs for creating interactive CLI tools.
Swift
443
star
5

leaf

๐Ÿƒ An expressive, performant, and extensible templating language built for Swift.
Swift
412
star
6

jwt

Vapor JWT provider
Swift
310
star
7

docs

๐Ÿ“– Documentation markdown for all Vapor packages.
Swift
309
star
8

postgres-nio

๐Ÿ˜ Non-blocking, event-driven Swift client for PostgreSQL.
Swift
282
star
9

toolbox

Simplifies common command line tasks when using Vapor
Swift
274
star
10

websocket-kit

WebSocket client library built on SwiftNIO
Swift
257
star
11

http

๐Ÿš€ Non-blocking, event-driven HTTP built on Swift NIO.
Swift
240
star
12

mysql-kit

๐Ÿฌ Pure Swift MySQL client built on non-blocking, event-driven sockets.
Swift
218
star
13

sql-kit

*๏ธโƒฃ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Swift
212
star
14

fluent-kit

Swift ORM (queries, models, and relations) for NoSQL and SQL databases
Swift
194
star
15

postgres-kit

๐Ÿ˜ Non-blocking, event-driven Swift client for PostgreSQL.
Swift
177
star
16

queues

A queue system for Vapor.
Swift
155
star
17

jwt-kit

๐Ÿ”‘ JSON Web Token (JWT) signing and verification (HMAC, ECDSA, EdDSA, RSA, PSS) with support for JWS and JWK
Swift
147
star
18

fluent-postgres-driver

๐Ÿ˜ PostgreSQL driver for Fluent.
Swift
141
star
19

api-template

๐Ÿ’ง A starting point for Vapor APIs.
Swift
136
star
20

open-crypto

๐Ÿ”‘ Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Swift
133
star
21

routing-kit

๐Ÿš High-performance trie-node router.
Swift
122
star
22

apns

Helpful extensions and abstractions for using APNSwift
Swift
104
star
23

service

๐Ÿ“ฆ Dependency injection / inversion of control framework.
Swift
84
star
24

mysql-nio

๐Ÿฌ Non-blocking, event-driven Swift client for MySQL.
Swift
82
star
25

core

๐ŸŒŽ Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
Swift
77
star
26

fluent-mysql-driver

๐Ÿ–‹๐Ÿฌ Swift ORM (queries, models, relations, etc) built on MySQL.
Swift
77
star
27

async-kit

Sugary extensions for the SwiftNIO library
Swift
71
star
28

fluent-sqlite-driver

Fluent driver for SQLite
Swift
67
star
29

template

Used by Vapor Toolboxโ€™s new project command
Swift
61
star
30

sqlite-kit

Non-blocking SQLite client library with SQL builder built on SwiftNIO
Swift
57
star
31

validation

โœ… Extensible data validation library (name, email, etc)
Swift
56
star
32

auth

๐Ÿ‘ค Authentication and Authorization framework for Fluent.
Swift
53
star
33

sqlite-nio

Non-blocking wrapper for libsqlite3-dev using SwiftNIO
C
51
star
34

template-kit

๐Ÿ“„ Easy-to-use foundation for building powerful templating languages in Swift.
Swift
44
star
35

leaf-kit

๐Ÿƒ An expressive, performant, and extensible templating language built for Swift.
Swift
44
star
36

docs-cn

๐Ÿ‡จ๐Ÿ‡ณ Chinese translation of Vapor's documentation markdown.
HTML
43
star
37

web-template

A starting point for web applications
Swift
42
star
38

website

Vapor's website running on Vapor and Vue
Vue
42
star
39

url-encoded-form

๐Ÿ“ Parse and serialize url-encoded form data with Codable support.
Swift
41
star
40

database-kit

๐Ÿ—„ Core services for creating database integrations.
Swift
40
star
41

auth-template

A starting point for Vapor applications using the auth provider.
Swift
35
star
42

university

Web application, iOS app, and API providing access to tutorials for the Vapor web framework.
Swift
24
star
43

fluent-mongo-driver

MongoDB support for Fluent built on MongoKittten.
Swift
23
star
44

queues-redis-driver

A Redis implementation for https://github.com/vapor/queues
Swift
22
star
45

design

Contains the reference designs and build pipeline to generate all design files for Vapor's sites
Swift
21
star
46

email

A common API for Vapor to integrate with different email providers
Swift
20
star
47

codable-kit

Conveniences for working with Swift's Codable protocols.
Swift
19
star
48

kafka

Swift Apacha Kafka (real-time data pipelines and streaming apps)
Swift
19
star
49

apt

Manage Vapor's Swift APT repository
Shell
17
star
50

blog

The Vapor Blog
Swift
16
star
51

penny-bot

The code that runs Penny ๐Ÿค–
Swift
14
star
52

docker

Swift
13
star
53

template-bare

A barebones template ready for use
Dockerfile
11
star
54

api-docs

Scripts and assets for Vapor's API documentation site at https://api.vapor.codes
Swift
9
star
55

redis-kit

Helpful extensions and abstractions for using RediStack
Swift
8
star
56

homebrew-tap

Homebrew Taps
Ruby
7
star
57

release-bot

Webhook-based GitHub bot that automatically tags new releases and posts to Discord when you merge PRs
Swift
6
star
58

template-fluent-postgres

A template ready for use configured with Fluent and PostgreSQL
Swift
5
star
59

ci

Support files and configurations for Vapor's CI
Swift
5
star
60

bot-github

A github bot to do things like interact with CI for the Vapor organization
Swift
5
star
61

template-fluent-postgres-leaf

A template ready for use configured with Leaf, Fluent and PostgreSQL
Swift
3
star
62

swift-codecov-action

A GitHub Action which performs Codecov.io uploads with additional support for Swift projects
Swift
3
star
63

swiftly-action

Simple one-step access to the Swiftly toolchain manager from GitHub Actions workflows
2
star
64

template-fluent-mysql

A template ready for use configured with Fluent and MySQL
Swift
2
star
65

swift-getting-started-web-server

The source code for the Getting Started Guide on Vapor on swift.org
Swift
1
star
66

docs-de

Deutsche รœbersetzung der Vapor-Dokumentation
HTML
1
star