A convenience umbrella package that re-exports all form coding functionality for Swift.
This package provides a single import for all form data encoding/decoding needs in Swift. It re-exports two independent packages:
- swift-url-form-coding - URL form encoding/decoding (
application/x-www-form-urlencoded) - swift-multipart-form-coding - Multipart form data with file uploads (
multipart/form-data)
Add this package to your Package.swift:
dependencies: [
.package(url: "https://github.com/coenttb/swift-form-coding", from: "0.1.0")
]Then add the product to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "FormCoding", package: "swift-form-coding")
]
)- macOS 14.0+
- iOS 17.0+
- tvOS 17.0+
- watchOS 10.0+
- Swift 6.1+
import FormCoding
// URL Form Encoding
struct LoginForm: Codable {
let username: String
let password: String
}
let encoder = Form.Encoder()
let form = LoginForm(username: "john", password: "secret")
let formData = try encoder.encode(form)
// Result: "username=john&password=secret"
// Multipart File Upload
let imageUpload = Multipart.FileUpload(
fieldName: "avatar",
filename: "profile.jpg",
fileType: .image(.jpeg),
maxSize: 5 * 1024 * 1024
)Use URL Form Coding when:
- Submitting simple form data without files
- Working with REST APIs that expect
application/x-www-form-urlencoded - You need PHP/Rails-style bracket notation for arrays
Use Multipart Form Coding when:
- Uploading files (images, documents, etc.)
- Mixing file uploads with form fields
- You need per-field content-type specification
If you only need one type of form coding, import the specific package instead:
// Just URL form encoding
dependencies: [
.package(url: "https://github.com/coenttb/swift-url-form-coding", from: "0.1.0")
]
// Just multipart file uploads
dependencies: [
.package(url: "https://github.com/coenttb/swift-multipart-form-coding", from: "0.1.0")
]Both underlying packages support optional URLRouting integration via Swift Package Manager traits:
// In your Package.swift
dependencies: [
.package(
url: "https://github.com/coenttb/swift-form-coding",
from: "0.1.0",
traits: ["URLRouting"] // Enable URLRouting trait
)
]When the URLRouting trait is enabled:
Form.Conversion<T>andMultipart.Conversion<T>conform toURLRouting.Conversion- URLRouting is re-exported for convenient access
- Convenience methods like
.form(_:)and.multipart(_:)are available
This is a minimal umbrella package with no code of its own. It simply re-exports:
URLFormCoding- URL-encoded form data supportMultipartFormCoding- Multipart form data with file uploadsURLRouting- Conditionally exported when URLRouting trait is enabled
The underlying packages are completely independent - they share no dependencies and can be used separately.
- ✅ Codable integration for form data
- ✅ Multiple array encoding strategies (accumulate, brackets, indexed)
- ✅ Custom date/data encoding strategies
- ✅ URLRouting integration
- ✅ RFC 2388 compliant
- ✅ Secure file upload validation
- ✅ Magic number (file signature) checking
- ✅ Configurable size limits
- ✅ Built-in file type support (images, documents, etc.)
- ✅ RFC 2045/2046/7578 compliant
- ✅ URLRouting integration
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- swift-url-form-coding - URL form encoding/decoding
- swift-multipart-form-coding - Multipart form data with file uploads