Differences

This shows you the differences between two versions of the page.

Link to this comparison view

frontend [2020/10/01 16:34]
paul created
frontend [2020/10/01 17:02] (current)
paul
Line 21: Line 21:
   ],   ],
 })) }))
 +</code>
 +
 +===== Dynamic Requests =====
 +
 +In Mirage JS there is a backend database that can be defined by Models and accessed using the Schema methods.
 +
 +<code javascript>
 +import { createServer, Model } from 'miragejs'
 +
 +export default function () {
 +  createServer({
 +
 +    models: {
 +      reminder: Model,
 +    },
 +
 +    routes() {
 +      this.get("/api/reminders", schema=> schema.reminders.all());
 +
 +      this.post("api/reminders", (schema, request) => {
 +        let attrs = JSON.parse(request.requestBody);
 +
 +        return schema.reminders.create(attrs);
 +      })
 +    },
 +  })
 +}
 </code> </code>
  • frontend.txt
  • Last modified: 2020/10/01 17:02
  • by paul