Created
February 6, 2017 09:43
-
-
Save vnglst/c6fec7b3af74f0f76634fd61220f58b2 to your computer and use it in GitHub Desktop.
Mocked version of request.js
This file contains 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 fs = require('fs') | |
const request = (url) => new Promise((resolve, reject) => { | |
// Get userID from supplied url string | |
const lastSlash = url.lastIndexOf('/') | |
const userID = url.substring(lastSlash + 1) | |
// Load user json data from a file in de subfolder for mock data | |
fs.readFile(`./src/api/__mockData__/${userID}.json`, 'utf8', (err, data) => { | |
if (err) reject(err) | |
// Parse the data as JSON and put in the key entity (just like the request library does) | |
resolve({ entity: JSON.parse(data) }) | |
}) | |
}) | |
export default request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dutch typo alert: replace
in de subfolder
by
in the subfolder