Structures
The following structures are available globally.
-
A set of values representing the format of a response body.
This struct is intended to be “enum-like” and values should be accessed via the public static stored properties.
Note
An enum was not used here because currently enums are always exhaustive. This means adding a case to an enum is a breaking change. In order to keep such additions non-breaking we have used an “enum-like” struct instead. This means code usingBodyFormat
should always handle unrecognisedBodyFormat
values (eg in a default case of a switch).UnsupportedBodyFormatError
may be used in this situation.Usage Example:
See morelet format = BodyFormat.json
Declaration
Swift
public struct BodyFormat : Equatable
-
An error that may be thrown when a particular instance of
See moreBodyFormat
is not supported.Declaration
Swift
public struct UnsupportedBodyFormatError : Error
-
An error representing a failed request. This definition is intended to be used by both the client side (e.g. KituraKit) and server side (e.g. Kitura) of the request (typically a HTTP REST request).
Usage Example:
In this example, the
RequestError
is used in a Kitura server Codable route handler to indicate the request has failed because the requested record was not found.
See morerouter.get("/users") { (id: Int, respondWith: (User?, RequestError?) -> Void) in ... respondWith(nil, RequestError.notFound) ... }
Declaration
Swift
public struct RequestError : RawRepresentable, Equatable, Hashable, Comparable, Error, CustomStringConvertible
-
A codable struct containing the ordering information
Usage Example:
To order ascending by name and descending by age, we would write:
See moreOrdering(by: .asc("name"), .desc("age"))
Declaration
Swift
public struct Ordering : Codable
-
A codable struct containing the pagination information
Usage Example:
To get only the first 10 values, we would write:
Pagination(size: 10)
To get the 11th to 20th values, we would write:
See morePagination(start: 10, size: 10)
Declaration
Swift
public struct Pagination : Codable
-
A codable struct enabling greater than filtering
Usage Example:
To filter with greaterThan on age which is an Integer, we would write:
struct MyQuery: QueryParams { let age: GreaterThan<Int> } let query = MyQuery(age: GreaterThan(value: 8))
In a URL it would translate to:
?age=8
Note: The “age=8” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct GreaterThan<I> : Operation where I : Identifier
-
A codable struct enabling greater than or equal filtering
Usage Example:
To filter with greater than or equal on age which is an Integer, we would write:
struct MyQuery: QueryParams { let age: GreaterThanOrEqual<Int> } let query = MyQuery(age: GreaterThanOrEqual>(value: 8))
In a URL it would translate to:
?age=8
Note: The “age=8” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct GreaterThanOrEqual<I> : Operation where I : Identifier
-
A codable struct enabling lower than filtering
Usage Example:
To filter with lower than on age, we would write:
struct MyQuery: QueryParams { let age: LowerThan<Int> } let query = MyQuery(age: LowerThan(value: 8))
In a URL it would translate to:
?age=8
Note: The “age=8” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct LowerThan<I> : Operation where I : Identifier
-
A codable struct enabling lower than or equal filtering
Usage Example:
To filter with lower than or equal on age, we would write:
struct MyQuery: QueryParams { let age: LowerThanOrEqual<Int> } let query = MyQuery(age: LowerThanOrEqual(value: 8))
In a URL it would translate to:
?age=8
Note: The “age=8” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct LowerThanOrEqual<I> : Operation where I : Identifier
-
A codable struct enabling to filter with an inclusive range
Usage Example:
To filter on age using an inclusive range, we would write:
struct MyQuery: QueryParams { let age: InclusiveRange<Int> } let query = MyQuery(age: InclusiveRange(start: 8, end: 14))
In a URL it would translate to:
?age=8,14
Note: The “age=8,14” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct InclusiveRange<I> : Operation where I : Identifier
-
A codable struct enabling to filter with an exlusive range
Usage Example:
To filter on age using an exclusive range, we would write:
struct MyQuery: QueryParams { let age: ExclusiveRange<Int> } let query = MyQuery(age: ExclusiveRange(start: 8, end: 14))
In a URL it would translate to:
?age=8,14
Note: The “age=8,14” format is not an API but an implementation detail that could change in the future.
See moreDeclaration
Swift
public struct ExclusiveRange<I> : Operation where I : Identifier