Skip to content

Instantly share code, notes, and snippets.

@vnglst
Created February 6, 2017 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vnglst/c6fec7b3af74f0f76634fd61220f58b2 to your computer and use it in GitHub Desktop.
Save vnglst/c6fec7b3af74f0f76634fd61220f58b2 to your computer and use it in GitHub Desktop.
Mocked version of request.js
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
@jawn
Copy link

jawn commented Oct 29, 2018

Dutch typo alert: replace
in de subfolder
by
in the subfolder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment