Library Moduleswift-http-types 1.3.1HTTPTypes

HTTPTypes

A set of version-independent HTTP currency types.

index.md
import HTTPTypes

Module information

Declarations
234
Symbols
359

Coverage

83.3 percent of the declarations in HTTPTypes are fully documented16.7 percent of the declarations in HTTPTypes are indirectly documented

Declarations

1.3 percent of the declarations in HTTPTypes are operators69.7 percent of the declarations in HTTPTypes are initializers, type members, or enum cases21.8 percent of the declarations in HTTPTypes are instance members1.7 percent of the declarations in HTTPTypes are instance subscripts4.7 percent of the declarations in HTTPTypes are structures0.9 percent of the declarations in HTTPTypes are typealiases

Interfaces

100.0 percent of the declarations in HTTPTypes are unrestricted
Module stats and coverage details

Overview

HTTPRequest represents an HTTP request message, including its method, scheme, authority, path, and header fields.

HTTPResponse represents an HTTP response message, including its status and header fields.

HTTPFields represents a list of HTTP header or trailer fields.

Getting Started

Create a request

let request = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/")

Create a request from a Foundation URL

var request = HTTPRequest(method: .get, url: URL(string: "https://www.example.com/")!)
request.method = .post
request.path = "/upload"

Create a response

let response = HTTPResponse(status: .ok)

Access and modify header fields

extension HTTPField.Name {
    static let myCustomHeader = Self("My-Custom-Header")!
}

// Set
request.headerFields[.userAgent] = "MyApp/1.0"
request.headerFields[.myCustomHeader] = "custom-value"
request.headerFields[values: .acceptLanguage] = ["en-US", "zh-Hans-CN"]

// Get
request.headerFields[.userAgent] // "MyApp/1.0"
request.headerFields[.myCustomHeader] // "custom-value"
request.headerFields[.acceptLanguage] // "en-US, zh-Hans-CN"
request.headerFields[values: .acceptLanguage] // ["en-US", "zh-Hans-CN"]