URLEncodedForm

main

Parse and serialize url-encoded form data with Codable support.
forXifLess/URLEncodedForm

Swift Platforms Swift Package Manager

URLEncodedForm

Parse and serialize url-encoded form data with Codable support.

🙏🏻 Notice

  • This is an (En/De)coder that converts URL query item parameters to Codable.
  • The original source has been modified to use the url-encoded-form created by the Vapor team through Foundation.

Installation

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/interactord/URLEncodedForm", .upToNextMajor(from: "1.0.0"))
]

✍🏻 Usage

It supports Codable provided by the Swift Foundation.

struct MyInfo: Codable {
  let height: Double
  let name: String
  let friends: [String]
  let family: Family

  struct Family: Codable {
    let names: [String]
  }
}

let me = MyInfo(
  height: 172.2,
  name: "Scott",
  friends: ["tom", "john", "mike"],
  family: .init(
    names: ["Father", "Mother", "Brother"]))

do {
  let data = try URLEncodedFormEncoder().encode(me)
  print(String(data: data, encoding: .utf8) ?? "nil")

  let origin = "name=Scott&height=172.2&friends[]=tom&friends[]=john&friends[]=mike&family[names][]=Father&family[names][]=Mother&family[names][]=Brother"
  let obj = try URLEncodedFormDecoder().decode(MyInfo.self, from: origin)
  print(obj)
} catch {
  print(error)
}

License

URLEncodedForm is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Apr 23 2024 15:54:23 GMT-0900 (Hawaii-Aleutian Daylight Time)