Get a full fake REST API with zero coding in less than 30 seconds
Quién lo usa: JSONPlaceholder
db.json:
{
"candidatos": [
{
"candidato": {
"nombre": "Alberto Mayol",
"foto": "https://pbs.twimg.com/profile_images/849674213740785664/DxVcm4S4.jpg",
"url": "",
"twitter": "https://twitter.com/MayolPresidente",
"facebook": ""
},
"partido": {
"nombre": "Frente Amplio",
"logo": "https://upload.wikimedia.org/wikipedia/commons/3/37/Frente_Amplio_Chile_2017.png"
},
...
server.json:
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3000
server.use(middlewares);
server.use(router);
server.use(jsonServer.bodyParser);
server.use((req, res, next) => {
if (req.method === 'POST') {
req.body.createdAt = Date.now();
}
next();
})
server.listen(port, () => {
console.log('JSON Server is running # localhost:' + port);
});
bomberos-cl-api | repositorio | demo