Last active
          June 5, 2019 17:33 
        
      - 
      
 - 
        
Save murajun1978/46f642c7f0288b93e17e595b5dda3e0f to your computer and use it in GitHub Desktop.  
    Functional programming in JavaScript
  
        
  
    
      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
    
  
  
    
  | const fetch = require("node-fetch"); | |
| export const fetchClient = baseUrl => endpoint => (success, failure) => { | |
| fetch(baseUrl + endpoint) | |
| .then(res => res.json()) | |
| .then(success) | |
| .catch(failure); | |
| }; | 
  
    
      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
    
  
  
    
  | import { fetchClient } from './fetchClient'; | |
| const github = fetchClient('https://api.github.com'); | |
| export const getGithubUsers = github('/users'); | 
  
    
      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
    
  
  
    
  | import { fetchClient } from './fetchClient'; | |
| const gitlab = fetchClient('https://gitlab.com/api/v4'); | |
| export getGitlabUsers = gitlab('/users'); | 
  
    
      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
    
  
  
    
  | import { getGithubUsers } from './github'; | |
| import { getGitlabUsers } from './gitlab'; | |
| getGithubUsers(data => console.log('Success!', data), err => console.log('Failure!', err); | |
| getGitlabUsers(data => console.log('Success!', data), err => console.log('Failure!', err); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment