Created
February 4, 2020 02:21
-
-
Save fkleuver/f8a4792faf4addc4efcb84fc6672841b 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; | |
| 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