Saturday, November 28, 2015

TypeScript builder pattern for a complex http request object that provides the client with a fluent API

Real world implementation of the builder pattern in TypeScript for building a complex http request object that provides the client with a fluent API

https://github.com/joelpalmer/Typescript--Builder-Pattern

If you wanted to use it inside of an Angular directive like I am in a real project...
scope: {},
        link: function (scope:ISidebarScope) {

            scope.Utils = Utils;
            var myRequest = new scope.Utils.RequestBuilder("get").setScheme("http").setPath("mypath").setHost("localhost").setPort("9999").build();

            console.log("My Request: " + myRequest.toString());

            var a = <HTMLAnchorElement> document.getElementById("aOutput");
            a.href = myRequest.toString();