Classes
The following classes are available globally.
-
The Cauli class is the starting point of the Cauli framework. Use the perconfigured
See moreCauli.shared
or create your own instance. Please check the Readme.md for more information.Declaration
Swift
public class Cauli
-
A
See moreFindReplaceFloret
usesRecordModifier
s to modify aRecord
before sending a request and after receiving a response. Use multiple instances of theFindReplaceFloret
s to group certain RecordModifiers under a given name.Declaration
Swift
public class FindReplaceFloret : InterceptingFloret
-
The
See moreHTTPBodyStreamFloret
can modify aRecord
where the request uses ahttpBodyStream
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 inspectRecord
s in the storage or want to modify the requests body before it is sent to the server.Declaration
Swift
public class HTTPBodyStreamFloret : InterceptingFloret
-
Undocumented
See moreDeclaration
Swift
public class InspectorFloretFormatter : InspectorFloretFormatterType
-
The InspectorFloret lets you browse through and share your requests and responses from within the application. Just open
Cauli
s viewController.You can
- browse through all stored
Records
. - inspect details of a
Record
. - share details of a
Record
. - filter
Record
s by the request URL.
Declaration
Swift
public class InspectorFloret : DisplayingFloret
- browse through all stored
-
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 theFindReplaceFloret
.Example configuration. For more examples check the
Mapping
documentation.
See morelet 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])
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 recordedMockFloret
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.
See more// 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) }
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
Declaration
Swift
public class NoCacheFloret : FindReplaceFloret