Type Aliases

The following type aliases are available globally.

Codable Type Aliases

  • The ResultClosure is used by other Codable aliases when responding with only a RequestError is needed.

    The following two typealiases make use of ResultClosure:

     public typealias NonCodableClosure = (@escaping ResultClosure) -> Void
    
     public typealias IdentifierNonCodableClosure<Id: Identifier> = (Id, @escaping ResultClosure) -> Void
    

    Declaration

    Swift

    public typealias ResultClosure = (RequestError?) -> Void
  • The CodableResultClosure is used by other Codable aliases when responding with an object which conforms to Codable, or a RequestError is needed.

    The following two typealiases make use of CodableResultClosure:

     public typealias IdentifierCodableClosure<Id: Identifier, I: Codable, O: Codable> = (Id, I, @escaping CodableResultClosure<O>) -> Void
    
     public typealias CodableClosure<I: Codable, O: Codable> = (I, @escaping CodableResultClosure<O>) -> Void
    

    Declaration

    Swift

    public typealias CodableResultClosure<O> = (O?, RequestError?) -> Void where O : Decodable, O : Encodable
  • The CodableArrayResultClosure is used by other Codable aliases when responding with an array of objects which conform to Codable, or a RequestError is needed.

    The following typealias makes use of CodableArrayResultClosure:

     public typealias CodableArrayClosure<O: Codable> = (@escaping CodableArrayResultClosure<O>) -> Void
    

    Declaration

    Swift

    public typealias CodableArrayResultClosure<O> = ([O]?, RequestError?) -> Void where O : Decodable, O : Encodable
  • The IdentifierCodableArrayResultClosure is used by other Codable aliases when responding with an array of tuples containing an identifier and a Codable object, or a RequestError.

    The following typealias makes use of IdentifierCodableArrayResultClosure:

     public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<[Id, O]?>) -> Void
    

    Declaration

    Swift

    public typealias IdentifierCodableArrayResultClosure<Id, O> = ([(Id, O)]?, RequestError?) -> Void where Id : Identifier, O : Decodable, O : Encodable
  • This is used to perform a series of actions which use an object conforming to Identifier and an object conforming to Codable. After which you want to respond with an object which conforms to Codable, which is of the same type as the object passed as a parameter, or respond with an Identifier or RequestError.

    The following typealias makes use of IdentifierCodableResultClosure:

     public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<Id, O>) -> Void
    

    Declaration

    Swift

    public typealias IdentifierCodableResultClosure<Id, O> = (Id?, O?, RequestError?) -> Void where Id : Identifier, O : Decodable, O : Encodable
  • The IdentifierCodableClosure is used to perform a series of actions utilising an object conforming to Identifier and an object conforming to ‘Codable’, then respond with an object which conforms to Codable, which is of the same type as the object passed as a parameter, or responding with a RequestError in the form of a CodableResultClosure.

    By default Int has conformity to Identifier. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error, passing nil for the User?. If no errors occurred and you have a User, you can just respond with the user, passing nil as the RequestError? value.

    Usage Example:

    public struct User: Codable {
      ...
    }
    
    var userStore: [Int, User] = [...]
    
    router.put("/users") { (id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
      guard let oldUser = self.userStore[id] else {
          respondWith(nil, .notFound)
          return
      }
    
      ...
    
      respondWith(user, nil)
    }
    

    Declaration

    Swift

    public typealias IdentifierCodableClosure<Id, I, O> = (Id, I, @escaping CodableResultClosure<O>) -> Void where Id : Identifier, I : Decodable, I : Encodable, O : Decodable, O : Encodable
  • The CodableClosure is used to perform a series of actions utilising an object conforming to Identifier, then respond with an object which conforms to Codable, which is of the same type as the object passed as a parameter, or responding with a RequestError in the form of a CodableResultClosure.

    If no errors occurred and you have a User, you can just respond with the user by passing nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error and passing nil for the User?.

    Usage Example:

    public struct User: Codable {
      ...
    }
    
    router.post("/users") { (user: User, respondWith: (User?, RequestError?) -> Void) in
      if databaseConnectionIsOk {
          ...
          respondWith(user, nil)
      } else {
          ...
          respondWith(nil, .internalServerError)
      }
    }
    

    Declaration

    Swift

    public typealias CodableClosure<I, O> = (I, @escaping CodableResultClosure<O>) -> Void where I : Decodable, I : Encodable, O : Decodable, O : Encodable
  • The CodableIdentifierClosure is used to perform a series of actions utilising an object conforming to Identifier, then respond with an object which conforms to Codable, and/or an object conforming to Identifier or responding with a RequestError in the form of a IdentifierCodableResultClosure.

    If no errors occurred and you have a User and the corresponding identifier, you can just respond with the identifier and user, and pass nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error and passing nil for Int? and nil for User?.

    Usage Example:

    public struct User: Codable {
      ...
    }
    
    router.post("/users") { (user: User, respondWith: (Int?, User?, RequestError?) -> Void) in
      if databaseConnectionIsOk {
          ...
          respondWith(id, user, nil)
      } else {
          ...
          respondWith(nil, nil, .internalServerError)
      }
    }
    

    Declaration

    Swift

    public typealias CodableIdentifierClosure<I, Id, O> = (I, @escaping IdentifierCodableResultClosure<Id, O>) -> Void where I : Decodable, I : Encodable, Id : Identifier, O : Decodable, O : Encodable
  • The NonCodableClosure is used to perform a series of actions then respond with a RequestError in the form of a ResultClosure.

    If no errors occurred you can just pass nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error.

    Usage Example:

    router.delete("/users") { (respondWith: (RequestError?) -> Void) in
        if databaseConnectionIsOk {
          ...
          respondWith(nil)
        } else {
          respondWith(.internalServerError)
          ...
        }
    }
    

    Declaration

    Swift

    public typealias NonCodableClosure = (@escaping ResultClosure) -> Void
  • The IdentifierNonCodableClosure is used to perform a series of actions utilising an object which conforms to Identifier, then respond with a RequestError in the form of a ResultClosure.

    If no errors occurred you can just pass nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error.

    Usage Example:

    router.delete("/users") { (id: Int, respondWith: (RequestError?) -> Void) in
      if databaseConnectionIsOk {
          ...
          respondWith(nil)
      } else {
          ...
          respondWith(.internalServerError)
      }
    }
    

    Declaration

    Swift

    public typealias IdentifierNonCodableClosure<Id> = (Id, @escaping ResultClosure) -> Void where Id : Identifier
  • The CodableArrayClosure is used to perform a series of actions then respond with an array of objects conforming to Codable or a RequestError in the form of a CodableArrayResultClosure.

    If no errors occurred and you have an array of Users you can just respond with the users by passing nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error and passing nil for the [User]?.

    Usage Example:

    router.get("/users") { (respondWith: ([User]?, RequestError?) -> Void) in
      if databaseConnectionIsOk {
          ...
          respondWith(users, nil)
      } else {
          ...
          respondWith(nil, .internalServerError)
      }
    }
    

    Declaration

    Swift

    public typealias CodableArrayClosure<O> = (@escaping CodableArrayResultClosure<O>) -> Void where O : Decodable, O : Encodable
  • The IdentifierCodableArrayClosure is used to perform a series of actions then respond with an array of tuples containing an identifier and a Codable object, or a RequestError, in the form of a IdentifierCodableArrayResultClosure.

    If no errors occurred and you have an array of Users you can just respond with the users by passing nil as the RequestError? value. In this example, if there has been an error you can use the respondWith call to respond with an appropriate error and passing nil for the [User]?.

    Usage Example:

    router.get("/users") { (respondWith: ([(Int, User)]?, RequestError?) -> Void) in
       if databaseConnectionIsOk {
           ...
           respondWith([(Int, User)], nil)
       } else {
           ...
           respondWith(nil, .internalServerError)
       }
    }
    

    Declaration

    Swift

    public typealias IdentifierCodableArrayClosure<Id, O> = (@escaping IdentifierCodableArrayResultClosure<Id, O>) -> Void where Id : Identifier, O : Decodable, O : Encodable
  • The SimpleCodableClosure is used to perform a series of actions, then respond with an object conforming to Codable or a RequestError in the form of a CodableResultClosure.

    Usage Example:

    public struct Status: Codable {
      ...
    }
    
    router.get("/status") { (respondWith: (Status?, RequestError?) -> Void) in
      ...
      respondWith(status, nil)
    }
    

    Declaration

    Swift

    public typealias SimpleCodableClosure<O> = (@escaping CodableResultClosure<O>) -> Void where O : Decodable, O : Encodable
  • The IdentifierSimpleCodableClosure is used to perform a series of actions utilising an object which conforms to Identifier, then respond with an object conforming to Codable or a RequestError in the form of a CodableResultClosure.

    If there has been an error you can use the respondWith call to respond with an appropriate error and passing nil for the User?. In this example, if no errors occurred and you have a User you can just respond with the user by passing nil as the RequestError? value.

    Usage Example:

    public struct User: Codable {
      ...
    }
    
    var userStore: [Int, User] = (...)
    
    router.get("/users") { (id: Int, respondWith: (User?, RequestError?) -> Void) in
      guard let user = self.userStore[id] else {
          respondWith(nil, .notFound)
          return
      }
      ...
      respondWith(user, nil)
    }
    

    Declaration

    Swift

    public typealias IdentifierSimpleCodableClosure<Id, O> = (Id, @escaping CodableResultClosure<O>) -> Void where Id : Identifier, O : Decodable, O : Encodable