create

fun create(name: String, baseUrl: String? = null, client: () -> OkHttpClient): OkHttpSender

Creates a sender that the Send form lists as name.

Lustro calls client only when a request is sent through this sender, and keeps the client it returns. So a client that has to be built after Lustro, because it carries the interceptor from Lustro.networkInterceptor(), can still be the sender, and the requests sent through it are captured.

Parameters

name

the name the Send form lists the sender under; must not be blank, and must be unique among the senders of one tab.

baseUrl

the absolute http or https URL that a relative URL resolves against: the path is appended to it, so https://api.example.com/v1 and /items give https://api.example.com/v1/items. null (the default) means the sender takes absolute URLs only.

client

returns the client to send through. Called off the main thread, at the first send.

Throws

when name is blank or baseUrl is not an absolute http or https URL.


@JvmName(name = "createWithBaseUrlProvider")
fun create(name: String, baseUrlProvider: () -> String?, client: () -> OkHttpClient): OkHttpSender

Creates a sender that the Send form lists as name, with a base URL that can change while the app runs, such as after a switch in the app's server picker.

The tab calls baseUrlProvider for each send of a relative URL and each time it lists the senders, off the main thread. When it returns null, the sender takes absolute URLs only until it returns a URL again. A send of a relative URL fails with a 400 and field: "baseUrl" when the provider throws, or returns a URL that is not an absolute http or https URL. An absolute URL is sent without calling it.

Lustro calls client only when a request is sent through this sender, and keeps the client it returns, as with the other create.

Java callers find this factory as createWithBaseUrlProvider, as create(name, null, client) would otherwise match both factories.

Parameters

name

the name the Send form lists the sender under; must not be blank, and must be unique among the senders of one tab.

baseUrlProvider

returns the absolute http or https URL that a relative URL resolves against now, or null.

client

returns the client to send through. Called off the main thread, at the first send.

Throws