【问题标题】:admin-on-rest Using PATCH methodadmin-on-rest 使用 PATCH 方法
【发布时间】:2017-06-07 21:29:04
【问题描述】:

我是一名初级节点开发人员,我正在尝试使用 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,但对它的工作原理有点困惑?我想我只是不知道从哪里开始。

【问题讨论】:

    标签: reactjs express admin-on-rest


    【解决方案1】:

    如果现在问题仍然存在,请检查我正在使用的一些地方来设置我的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}>
    

    【讨论】:

    • 感谢您的回答!所以我现在无法让我的 customRestClient 正常工作,特别是我尝试从 admin-on-rest 导入的第一行?import { queryParameters, fetchJson } from 'admin-on-rest/src/util/fetch' 不起作用
    • 我只是简单地从 aor ../node_modules/admin-on-rest/src/util/fetch.js 复制到我的 src 文件夹并从它导入为 './fetch.js'跨度>
    猜你喜欢
    • 2015-06-15
    • 1970-01-01
    • 2015-07-11
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多