Junivator Mock API

node v8.17.0
version: 0.1.0
endpointsharetweet
const runkitExpress = require('@runkit/runkit/express-endpoint/1.0.0'); const app = runkitExpress(exports); const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); next(); }); app.use(function errorHandler (err, req, res, next) { res.status(500) res.render('error', { error: err }) }) app.options('/*', function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,OPTIONS'); res.send(200); }); app.get('/', function(req, res) { const msg = `👋 Hello. This is a *very* preliminary mock API response for use with Juniper's Junivator experience. It currently just returns the same data, randomized every time. The last page will always be 3.`; const options = parseOptions(req.query); return res.json(wrapResult(getRandomizedUserData(), options, msg)); });
// Preps data for response function wrapResult(data, options, description = '👌') { const length = Array.isArray(data) ? data.length : data === null || data === undefined ? 0 : 1; return { message: `${description}`, length: length, data: { entries: data, page: options.page, hasNextPage: options.hasNextPage } }; } // Parses and normalizes options passed in query function parseOptions(query) { const numberOptnIsValid = num => typeof num === 'number' && !isNaN(num) && num > -1; const pageInput = parseInt(query.page, 10); const page = numberOptnIsValid(pageInput) ? (pageInput > 0 ? pageInput : 1) : 1; return { page: page, hasNextPage: page < 3 }; } // Fisher-Yates shuffle algorythm function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; }
function getRandomizedUserData() { const data = getUserData().slice(); return shuffle(data) } function getUserData() { return [ { first_name: 'Eloisa', last_name: 'Rau', job_title: 'Principal Brand Producer', url: 'https://example.com', causes: ['advocacy', 'animals'], image_small: 'https://picsum.photos/500/450/?random', last_updated: '10/11/2017', start_date: '11/11/2000', location: 'SF', department: 'Marketing', role: 'Technical Marketing Engineer', hobbies: ['concerts', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Zackary', last_name: 'Nader', job_title: 'Product Security Executive', url: 'https://example.com', causes: ['arts', 'children'], image_small: 'https://picsum.photos/600/400/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Creative', role: 'Project Manager', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Anabel', last_name: 'Satterfield', job_title: 'Senior Integration Technician', url: 'https://example.com', causes: ['technology', 'community'], image_small: 'https://picsum.photos/500/300/?random', last_updated: '02/14/2018', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Project Manager', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Tyson', last_name: 'Schulist', job_title: 'National Accountability Manager', url: 'https://example.com', causes: ['technology', 'community'], image_small: 'https://picsum.photos/600/400/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Full Stack Developer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Lavonne', last_name: 'Rowe', job_title: 'Global Optimization Consultant', url: 'https://example.com', image_small: 'https://picsum.photos/350/350/?random', causes: ['education', 'safety'], last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Technical Support Engineer', hobbies: ['cooking', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Brad', last_name: 'Casemore', job_title: 'Research Director, Datacenter Networks', url: 'https://example.com', image_small: 'https://picsum.photos/550/450/?random', causes: ['education', 'safety', 'environment'], last_updated: '03/14/2016', start_date: '02/14/2018', location: 'SF', department: 'Technology', role: 'Technical Support Engineer', hobbies: ['basketball', 'biking'] }, { first_name: 'Mike', last_name: 'Marcellin', job_title: 'Senior Vice President and Chief Marketing Officer', url: 'https://example.com', causes: ['education', 'medicine'], image_small: 'https://picsum.photos/550/400/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Software Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Eloisa', last_name: 'Rau', job_title: 'Principal Brand Producer', url: 'https://example.com', causes: ['advocacy', 'animals'], image_small: 'https://picsum.photos/550/600/?random', last_updated: '10/11/2017', start_date: '11/11/2000', location: 'SF', department: 'Marketing', role: 'Account Manager', hobbies: ['concerts', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Zackary', last_name: 'Nader', job_title: 'Product Security Executive', url: 'https://example.com', causes: ['education', 'medicine'], image_small: 'https://picsum.photos/500/450/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Creative', role: 'Software Engineering Manager', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Anabel', last_name: 'Satterfield', job_title: 'Senior Integration Technician', url: 'https://example.com', causes: ['immigrants', 'housing'], image_small: 'https://picsum.photos/450/600/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Software Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Tyson', last_name: 'Schulist', job_title: 'National Accountability Manager', url: 'https://example.com', causes: ['immigrants', 'housing'], image_small: 'https://picsum.photos/450/350/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Software Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Lavonne', last_name: 'Rowe', job_title: 'Global Optimization Consultant', url: 'https://example.com', causes: ['international', 'justice'], image_small: 'https://picsum.photos/500/400/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Software Engineer', hobbies: ['cooking', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Brad', last_name: 'Casemore', job_title: 'Research Director, Datacenter Networks', url: 'https://example.com', causes: ['international', 'justice'], image_small: 'https://picsum.photos/500/450/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SU', department: 'Finance', role: 'Payroll Specialist', hobbies: ['basketball', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Mike', last_name: 'Marcellin', job_title: 'Senior Vice President and Chief Marketing Officer', url: 'https://example.com', causes: ['religion', 'justice'], image_small: 'https://picsum.photos/400/500/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Data Platform Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Eloisa', last_name: 'Rau', job_title: 'Principal Brand Producer', url: 'https://example.com', causes: ['research'], image_small: 'https://picsum.photos/400/600/?random', last_updated: '10/11/2017', start_date: '11/11/2000', location: 'SF', department: 'Technology', role: 'Solution Consultant', hobbies: ['concerts', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Zackary', last_name: 'Nader', job_title: 'Product Security Executive', url: 'https://example.com', causes: ['recreation', 'other_areas'], image_small: 'https://picsum.photos/450/550/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Solution Consultant', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Anabel', last_name: 'Satterfield', job_title: 'Senior Integration Technician', url: 'https://example.com', causes: ['recreation'], image_small: 'https://picsum.photos/600/300/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Hardware Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Tyson', last_name: 'Schulist', job_title: 'National Accountability Manager', url: 'https://example.com', causes: ['recreation'], image_small: 'https://picsum.photos/450/550/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SU', department: 'Technology', role: 'Hardware Engineer', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Lavonne', last_name: 'Rowe', job_title: 'Global Optimization Consultant', url: 'https://example.com', causes: ['recreation'], image_small: 'https://picsum.photos/600/300/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Technology', role: 'Hardware Engineer', hobbies: ['cooking', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Brad', last_name: 'Casemore', job_title: 'Research Director, Datacenter Networks', url: 'https://example.com', causes: ['recreation'], image_small: 'https://picsum.photos/300/300/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Creative', role: 'Art Director', hobbies: ['basketball', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] }, { first_name: 'Mike', last_name: 'Marcellin', job_title: 'Senior Vice President and Chief Marketing Officer', url: 'https://example.com', causes: ['recreation'], image_small: 'https://picsum.photos/500/350/?random', last_updated: '03/14/2016', start_date: '11/11/2003', location: 'SF', department: 'Creative', role: 'Art Director', hobbies: ['board_games', 'biking'], books: ['memoir', 'self_help'], movies: ['comedy', 'family'] } ]; }
Loading…

no comments

    sign in to comment