Skip to content

Instantly share code, notes, and snippets.

@pgilad
Created March 20, 2018 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgilad/b7ca6df2fc171a055a9835089439154c to your computer and use it in GitHub Desktop.
Save pgilad/b7ca6df2fc171a055a9835089439154c to your computer and use it in GitHub Desktop.
A builder for requests
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