Last active
April 26, 2018 19:39
-
-
Save kazagkazag/5dd355c708e82e3b40d787aeaec41d20 to your computer and use it in GitHub Desktop.
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 faker = require("faker"); | |
server.get("/users/:id/articles", (request, response) => { | |
response.send(200, getArticlesForUser()); | |
}); | |
// you can create articles on the fly | |
// or prepare few articles upfront | |
// and just select them now | |
function getArticlesForUser() { | |
const howMany = faker.random.number({min: 1, max: 10}); | |
const articles = []; | |
for(let i = 0; i < howMany; i++) { | |
articles.push({ | |
title: faker.lorem.words(5), | |
content: faker.lorem.paragraphs(4), | |
createdAt: faker.date.recent() | |
}); | |
} | |
return articles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment