Skip to content
Commitwise
Menu

Fluent interface

An API whose methods return an object you can keep calling, so a configuration reads like a sentence.

Definition

In a fluent interface each call returns the same builder (or a new immutable copy), so calls chain: request.url(u).header(k, v).timeout(t). Builders, query DSLs and stream pipelines are common examples. Chains are easy to read, but a mutable builder shared between threads or reused after build() can leak settings between objects.

In practice

Java's HttpRequest.newBuilder(uri).header("Accept", "application/json").GET().build().

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.