Skip to content

Instantly share code, notes, and snippets.

@fkleuver
Created February 4, 2020 02:21
Show Gist options
  • Select an option

  • Save fkleuver/f8a4792faf4addc4efcb84fc6672841b to your computer and use it in GitHub Desktop.

Select an option

Save fkleuver/f8a4792faf4addc4efcb84fc6672841b to your computer and use it in GitHub Desktop.
function executeWithFetch(request) {
// EXERCISE FOR THE READER
}
function executeWithAxios(request) {
// EXERCISE FOR THE READER
}
function ClientBuilder() {
return (function () {
let baseUrl, headers, executor;
function forBaseUrl(_baseUrl) {
baseUrl = _baseUrl;
return { withHeaders };
}
function withHeaders(_headers) {
headers = _headers;
return { usingFetch, usingAxios };
}
function usingFetch() {
executor = executeWithFetch;
return { build };
}
function usingAxios() {
executor = executeWithAxios;
return { build };
}
function build() {
function post(endpoint, data) {
return executor({
url: `${baseUrl}${endpoint}`,
data,
method: 'POST',
headers,
});
}
function get(endpoint, params) {
return executor({
url: `${baseUrl}${endpoint}`,
params,
method: 'GET',
headers,
});
}
return { post, get };
}
return { forBaseUrl };
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment