...
/Solution: Design a URL Builder with Conditional Parameters
Solution: Design a URL Builder with Conditional Parameters
Build a fluent URL builder that dynamically serializes query parameters while enforcing the presence of a base path.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 2–6: We initialize an internal state with
base,params, andfilters, keeping URL segments separate. Thebasemust be explicitly provided before building.Lines 8–31: We define fluent setter methods for different URL components.
withPage,withLimit, andsortByadd pagination and sorting options toparams.filterBystores filter key-value pairs, supporting multiple dynamic filters.Each method returns
this, enabling flexible chaining. ...