Back to Kitura

MediaType

docs/Structs/MediaType.html

3.0.13.5 KB
Original Source

MediaType

public struct MediaType : CustomStringConvertible
extension MediaType: Equatable
extension MediaType: Hashable

The media type (formerly known as MIME type) is a standardized way to indicate the nature and format of a document. This struct consists of a catagorical topLevelType and specific subtype seperated by a “/” (e.g. “text/plain”). In HTTP, The media type is sent as the first section of the “Content-Type” header and is case insensitive.

Usage Example:

let mediaType = MediaType(type: .application, subtype: "json")
print(mediaType.description)
// Prints ("application/json")

`

                TopLevelType
                `

An enum of all recognized top-level media types (categories). See: https://www.iana.org/assignments/media-types/media-types.xhtml

See more

Declaration

Swift

public enum TopLevelType : String

Media type components

`

                topLevelType
                `

The topLevelType represents the category of the MediaType (e.g. “audio”).

Declaration

Swift

public let topLevelType: TopLevelType

`

                subType
                `

The subtype is the specific MediaType (e.g. “html”).

Declaration

Swift

public let subType: String

Initializers

`

                init(type:subType:)
                `

Initialize a MediaType instance with a TopLevelType type and String subtype. If no subtype is provided it will default to “*” representing all subtypes.

Usage Example:

let mediaType = MediaType(type: .application, subtype: "json")

Declaration

Swift

public init(type: TopLevelType, subType: String = "*")

`

                init(_:)
                `

Initialize a MediaType instance from a String. If no subtype is provided it will default to “*” representing all subtypes. If the string preceding the first “/” is not a valid TopLevelType the initializer will return nil.

Usage Example:

let mediaType = MediaType("application/json")

Declaration

Swift

public init?(_ mimeType: String)

Helper Constructors

`

                json
                `

Helper constructor for the “application/json” media type

Usage Example:

let mediaType = MediaType.json
print(mediaType.description)
// Prints ("application/json")

Declaration

Swift

public static let json: MediaType

`

                urlEncoded
                `

Helper constructor for the “application/x-www-form-urlencoded” media type

Usage Example:

let mediaType = MediaType.urlEncoded
print(mediaType.description)
// Prints ("application/x-www-form-urlencoded")

Declaration

Swift

public static let urlEncoded: MediaType

Protocol conformance

`

                description
                `

Returns the media type, as a String structured: topLevelType/subtype. Required for CustomStringConvertible conformance.

Usage Example:

print(mediaType.description)
// Prints ("application/json")

Declaration

Swift

public let description: String

`

                ==(_:_:)
                `

Compares two MediaTypes returning true if they are equal. Required for Equatable conformance.

`

                hashValue
                `