0

我是一名初级节点开发人员,我正在尝试使用 admin 来为我的 json api 快速运行一个管理面板。但是,我所有的更新请求都使用补丁而不是 put。我尝试在我的 restClient 中修改 UPDATE 方法,但这似乎是错误的(为简洁起见,删除了其余方法)

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 }
  }
}

对我来说这是有道理的,但是当我尝试编辑一个对象时,HTTP/1.1 404 Not Found <pre>Cannot PUT </pre> 我知道这在以前的版本中是不可能的,但我读了这个https://marmelab.com/blog/2017/03/10/admin- on-rest-0-9.html#http-patch但对它的工作原理有点困惑?我想我只是不知道从哪里开始。

4

1 回答 1

0

如果问题现在仍然存在,请检查我正在使用的一些地方来设置我的customRestClient.

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

在我的情况下,我使用 httpClient 添加自定义标头:

import httpClient from './httpClient';

以下:

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

最后:

<Admin title="Admin Panel" restClient={restClient}>
于 2017-06-11T20:35:50.630 回答