Classes

The following classes are available globally.

  • The Health class provides a concrete implementation of the HealthProtocol protocol that applications can instantiate and then register one or more health checks against. Once you have your health checks in place you can ask your Health instance for its status.

    Usage Example:

    One common use case for this Swift package is to integrate it into a Kitura-based application. In the code sample below, the health of the application is exposed through the /health endpoint. Cloud environments (e.g. Cloud Foundry, Kubernetes, etc.) can then use the status information returned from the /health endpoint to monitor and manage the Swift application instance.

    For further information and example code see our README and the Cloud Foundry documentation for using application health checks.

     import Health
    
     let health = Health()
    
     health.addCheck(check: MyCheck1())
     health.addCheck(check: myClosureCheck1)
    
     // Define /health endpoint that leverages Health
     router.get("/health") { request, response, next in
        let status = health.status
        if health.status.state == .UP {
            try response.status(.OK).send(status).end()
        } else {
            try response.status(.serviceUnavailable).send(status).end()
        }
     }
    
    See more

    Declaration

    Swift

    public class Health : HealthProtocol
  • Struct that encapsulates a DateFormatter implementation, specifically used by the Status struct.

    See more

    Declaration

    Swift

    public class StatusDateFormatter