DefaultBodyStrategy
public struct DefaultBodyStrategy : ResponseBodyDecodingStrategy
A default strategy for validating response bodies.
The DefaultBodyStrategy struct provides a default strategy for validating response bodies
by checking if the status code is between 200 (OK) and 300 (Multiple Choices).
It conforms to the ResponseBodyDecodingStrategy protocol and defines the
allowsEmptyContent(for:) and validate(statusCode:) methods.
Example usage:
@ResponseBodyWrapper<Body, DefaultBodyStrategy> var body: Body
-
Determines whether the decoding should fail when no content is returned.
Example usage:
let allowsEmpty = DefaultBodyStrategy.allowsEmptyContent(for: 204) print(allowsEmpty) // Output: falseDeclaration
Swift
public static func allowsEmptyContent(for _: Int) -> BoolReturn 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 = DefaultBodyStrategy.validate(statusCode: 200) print(isValid) // Output: trueDeclaration
Swift
public static func validate(statusCode: Int) -> BoolParameters
statusCodeThe HTTP status code of the response.
Return Value
A Boolean value indicating whether the status code is valid.
View on GitHub