0

I am a junior node developer and am trying out admin on rest to quickly run up an admin panel for my json api. However, all of my update requests use patch instead of put. I attempted revising the UPDATE method in my restClient but this seems wrong (the rest of the methods are removed for brevity)

export default (apiUrl, httpClient = fetchJson) => {
const convertRESTRequestToHTTP = (type, resource, params) => {
    let url = ''
    const options = {}
    switch (type) {
      case UPDATE:
        url = `${apiUrl}/${resource}/${params.id}`
        options.method = 'PATCH'
        options.body = JSON.stringify(params.data)
        break

    return { url, options }
  }
}

To me this makes sense but when I try to edit an object I get back HTTP/1.1 404 Not Found <pre>Cannot PUT </pre> I know that that this wasn't possible with previous versions but I read this https://marmelab.com/blog/2017/03/10/admin-on-rest-0-9.html#http-patch but was a little confused on how it works? I guess I just don't know where to start with this.

1 Answers1

0

if problem still is actual now, please check some places which are using by me to set my customRestClient.

// App.js
import customRestClient from './customRestClient';

in my case i'm using httpClient to add custom headers:

import httpClient from './httpClient';

below:

const restClient = customRestClient('my_api_url', httpClient);

and finally:

<Admin title="Admin Panel" restClient={restClient}>
Alexey
  • 601
  • 7
  • 17
  • Thanks for the answer! so I am having trouble getting my customRestClient working now, specifically, the first line where I am trying to import from admin-on-rest?`import { queryParameters, fetchJson } from 'admin-on-rest/src/util/fetch'` isn't working – Derek Kelmanson Jr. Jun 13 '17 at 14:39
  • i just simple copied from aor ../node_modules/admin-on-rest/src/util/fetch.js to my src folder and import from it as './fetch.js' – Alexey Jun 13 '17 at 14:43