Declaration

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.

Declaration

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.

Declaration

The MockFloret helps you to easily mock your network requests
for tests or to reproduce a bug.

Recording Requests

letmockFloret=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

letmockFloret=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,mockFloretinguardrequest.url?.host=="cauli.works"else{returnnil}returnmockFloret.resultForPath("default/foo")}// Maps all requests for the url path /api/florets to// a Not Found (404) response.addMapping(forUrlPath:"/api/florets"){request,_inResult<Response>.notFound(for:request)}