This is a version 2 only feature.
This is a great comparison of OO Builder vs Functional Builder patterns, so firstly how does the usage code compare:
RequestBuilder (OO Style):
Request request = get("/").header(ACCEPT, "Kittens").query("name", "Mimi").build();
Request.Builder (Functional Style)
Request request = get("/", header(ACCEPT, "Kittens"), query("name", "Mimi"));
Not much difference except you never have to call build() and that you never actually create Request.Builder is just a place to store some functions. So what are the trade offs:
Pros
- No extensibility lock in, all functions on Request.Builder are just static unary functions that take a Request and modify it in some way and then return it. You can create your own functions with out having to use inheritance, i.e its completely open.
- The code is way way simple, you can compose your functions and handle nested persistent data structures.
- It has a lot more features for less code, now you can convert between query, form, header, cookie parameters without me ever actually implementing specific code to do it.
- It's uniform, cookies behave exactly the same as headers even though they are nested in headers.
- It's more performant for nested structures as you can edit in place a bit like a zipper or lens.
Cons
- More static imports
- You can't do 'dot' navigation, always best to start by importing Request.Builder.* and then optimise afterwards.
- Not as familiar for most people.
NB: Obviously this is slightly unfair as RequestBuilder organically grew to the mess it is today!
Feedback always welcome
Dan