OptionalContentStrategy

public struct OptionalContentStrategy : ResponseBodyDecodingStrategy

A strategy for validating response bodies with status code 204.

The OptionalContentStrategy struct provides a strategy for validating response bodies with a status code of 204 (No Content). It conforms to the ResponseBodyDecodingStrategy protocol and defines the allowsEmptyContent(for:) and validate(statusCode:) methods.

Example usage:

@ResponseBodyWrapper<Body, OptionalContentStrategy> var body: Body
  • Determines whether the decoding should fail when no content is returned.

    Example usage:

    let allowsEmpty = OptionalContentStrategy.allowsEmptyContent(for: 204)
    print(allowsEmpty) // Output: true
    

    Declaration

    Swift

    public static func allowsEmptyContent(for statusCode: Int) -> Bool

    Parameters

    statusCode

    The HTTP status code of the response.

    Return Value

    A Boolean value indicating whether empty content is allowed.

  • Validates the HTTP status code to determine if it is within the acceptable range.

    Example usage:

    let isValid = OptionalContentStrategy.validate(statusCode: 200)
    print(isValid) // Output: true
    

    Declaration

    Swift

    public static func validate(statusCode: Int) -> Bool

    Parameters

    statusCode

    The HTTP status code of the response.

    Return Value

    A Boolean value indicating whether the status code is valid.