In this section, we are going to create the HTTP DELETE method that will be mocked by the MirageJS server. Follow these steps to create it:
- For the DELETE methods, we need to create a new file called delete.js in the src/server folder.
- For this recipe, we will make a generic patchFrom function that receives a key as an argument and returns a function. This returned function will parse the data property of the HTTP request body and return an internal function of the server schema that deletes a specific object with the id property, which was passed to the server via the route REST parameter. Using the key argument, the schema knows which table we are handling:
export const deleteFrom = key => (schema, request) =>
schema.db[key].remove(request.params.id);
export default {
deleteFrom,
};