How to manage DELETE 204 response status code with Rest Admin?

I am trying to integrate admin-on-rest with api sending 204 HTTP response without body on successful DELETE.

So DELETE I am getting the error:

REST response must contain data key

I am using jsonServerRestClient

and I am wondering how I could override this client so that it accepts 204 on DELETE and redirects the list?

+3


source to share


2 answers


so if my trivial answer has been converted to a comment please post it in more detail.

you can write your client. add this to App.js

import customRestClient from './customRestClient'

      



create customRestClient.js

and enter code from jsonServerRestClient.js

there in function convertHTTPResponseToREST

you can add

console.log(response);
console.log(type);
console.log(resource);
console.log(params);

      

and see what response

is the object containing the response code. In the case block, you can write your own behavior by adding DELETE. I hope this helps you

+1


source


Update the convertHTTPResponseToREST method in your rest client to handle responses for DELETE requests and enter a data key (which might just be an empty object).

eg.



const convertHTTPResponseToREST = (response, type, resource, params) => {
    ...
    switch (type) {
        case GET_LIST:
            ...
        case GET_MANY_REFERENCE:
            ...
        case CREATE:
            ...

        /* START OF MAGIC */

        case DELETE:
            return { data: { } };

        /* END OF MAGIC */

        default:
            ...
    }
};

      

I believe that redirecting back to the list after successful deletion is the default behavior.

0


source







All Articles