3

I'm trying to integrate admin-on-rest with an api sending a 204 HTTP response without a body on successful DELETE.

So on DELETE I get the error message :

REST response must contain a data key

I'm using jsonServerRestClient and I wonder how could I override this client so it accepts 204 on DELETE and redirects to the list ?

ExsiDev
  • 31
  • 2
  • oh, it's very like on my case http://stackoverflow.com/questions/43854617/admin-on-rest-how-to-set-path-for-list-elements see answer which written by @pelak – Alexey May 09 '17 at 23:35

2 Answers2

1

so, if my trivial answer was converted to comment write it more detail.

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

import customRestClient from './customRestClient'

create customRestClient.js and put 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 that response is object that contains code of response. In case block you can write your own behavior by adding DELETE. I hope, that it will help you

Alexey
  • 601
  • 7
  • 17
0

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

e.g.

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 a successful deletion is the default behaviour.

pythonjsgeo
  • 5,122
  • 2
  • 34
  • 47