Created
March 20, 2018 19:16
-
-
Save pgilad/b7ca6df2fc171a055a9835089439154c to your computer and use it in GitHub Desktop.
A builder for requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Request { | |
ajax = $.ajax; | |
baseURL = API_BASE_URL; | |
contentType = 'application/json'; | |
data = null; | |
dataType = 'json'; | |
global = true; | |
method = 'GET'; | |
params = null; | |
paramsSerializer = defaultParamsSerializer; | |
processData = false; | |
transformBody = data => JSON.stringify(data); | |
transformResponse = null; | |
url = ''; | |
static Builder() { | |
return new Request(); | |
} | |
withUrl(value) { | |
this.url = value; | |
return this; | |
} | |
withMethod(value) { | |
this.method = value; | |
return this; | |
} | |
build() { | |
return $.ajax({ | |
url: this.url, | |
method: this.method | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment