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