Classes

The following classes are available globally.

  • The Cauli class is the starting point of the Cauli framework. Use the perconfigured Cauli.shared or create your own instance. Please check the Readme.md for more information.

    See more

    Declaration

    Swift

    public class Cauli
  • A FindReplaceFloret uses RecordModifiers to modify a Record before sending a request and after receiving a response. Use multiple instances of the FindReplaceFlorets to group certain RecordModifiers under a given name.

    See more

    Declaration

    Swift

    public class FindReplaceFloret : InterceptingFloret
  • The HTTPBodyStreamFloret can modify a Record where the request uses a httpBodyStream instead of setting the data on the request itself. It will read all data from the stream and set it as data on the request. This is helpful if you want to inspect Records in the storage or want to modify the requests body before it is sent to the server.

    See more

    Declaration

    Swift

    public class HTTPBodyStreamFloret : InterceptingFloret
  • Undocumented

    See more

    Declaration

    Swift

    public class InspectorFloretFormatter : InspectorFloretFormatterType
  • The InspectorFloret lets you browse through and share your requests and responses from within the application. Just open Caulis viewController.

    You can

    • browse through all stored Records.
    • inspect details of a Record.
    • share details of a Record.
    • filter Records by the request URL.
    See more

    Declaration

    Swift

    public class InspectorFloret : DisplayingFloret
  • The MapRemoteFloret can modify the url before the request is performed. This is esp. helpful when using a staging or testing server.

    The MapRemoteFloret can only modify the url of a request. If you need to update headers please use the FindReplaceFloret.

    Example configuration. For more examples check the Mapping documentation.

    let httpsifyMapping = Mapping(name: "https-ify", sourceLocation: MappingLocation(scheme: "http"), destinationLocation: MappingLocation(scheme: "https"))
    let mapLocal = Mapping(name: "map local", sourceLocation: MappingLocation(), destinationLocation: MappingLocation(host: "localhost")
    let floret = MapRemoteFloret(mappings: [httpsifyMapping, mapLocal])
    Cauli([floret])
    
    See more

    Declaration

    Swift

    public class MapRemoteFloret : InterceptingFloret
  • The MockFloret helps you to easily mock your network requests for tests or to reproduce a bug.

    Recording Requests

    let mockFloret = MockFloret(mode: .record)
    

    If you create your MockFloret in recording mode it will record all requests and their responses (depending on the Cauli configuration). They will be serialized and stored in the document directory. The exact path will be printed in the console as “recoding to ...”.

    Mocking Requests

    let mockFloret = MockFloret(mode: .mock)
    

    If you create your MockFloret in mock mode it will search for a MockFloret folder in the bundle. If you used the record mode you can just copy over the recorded MockFloret folder. Make sure to select “Create folder references” if you drag the folder to Xcode. For every request the MockFloret will then search in this folder if there is any recorded response. If there are multiple it will return a random response.

    Manual Response Mapping

    You can use the addMapping functions to manually map a request to a specific response.

    // Maps all requests for the host cauli.works to the response
    // stored in the MockFloret/default/foo path.
    addMapping { request, mockFloret in
        guard request.url?.host == "cauli.works" else { return nil }
        return mockFloret.resultForPath("default/foo")
    }
    
    // Maps all requests for the url path /api/florets to
    // a Not Found (404) response.
    addMapping(forUrlPath: "/api/florets") { request, _ in
        Result<Response>.notFound(for: request)
    }
    
    See more

    Declaration

    Swift

    public class MockFloret : InterceptingFloret
  • The NoCacheFloret modifies the desigantedRequest and the response of a record to prevent returning cached data or writing data to the cache.

    On the designatedRequest it will:

    • change the cachePolicy to .reloadIgnoringLocalCacheData
    • remove the value for the If-Modified-Since key on allHTTPHeaderFields
    • remove the value for the If-None-Match key on allHTTPHeaderFields
    • change Cache-Control to no-cache

    On the response it will:

    • remove the value for the Last-Modified key on allHTTPHeaderFields
    • remove the value for the ETag key on allHTTPHeaderFields
    • change Expires to 0
    • change Cache-Control to no-cache
    See more

    Declaration

    Swift

    public class NoCacheFloret : FindReplaceFloret