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: false
Declaration
Swift
public static func allowsEmptyContent(for _: Int) -> Bool
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 = DefaultBodyStrategy.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.