Structures

The following structures are available globally.

  • Decodes instances of Decodable types from application/x-www-form-urlencoded Data.

    print(data) // "name=Vapor&age=3"
    let user = try URLEncodedFormDecoder().decode(User.self, from: data)
    print(user) // User
    

    URL-encoded forms are commonly used by websites to send form data via POST requests. This encoding is relatively efficient for small amounts of data but must be percent-encoded. multipart/form-data is more efficient for sending large data blobs like files.

    See Mozilla’s docs for more information about url-encoded forms.

    See more

    Declaration

    Swift

    public struct URLEncodedFormDecoder
  • Encodes Encodable instances to application/x-www-form-urlencoded data.

    print(user) /// User
    let data = try URLEncodedFormEncoder().encode(user)
    print(data) /// Data
    

    URL-encoded forms are commonly used by websites to send form data via POST requests. This encoding is relatively efficient for small amounts of data but must be percent-encoded. multipart/form-data is more efficient for sending large data blobs like files.

    See Mozilla’s docs for more information about url-encoded forms. NOTE: This implementation of the encoder does not support encoding booleans to “flags”.

    See more

    Declaration

    Swift

    public struct URLEncodedFormEncoder