标签: jsonapi-resources

如何防止Ember数据保存属性(即,只读属性)

我正在创建一个在线表单构建器,在前端使用Ember 2.0,在后端使用json_api_resources gem创建Rails 4.2.

在发布表单的过程中,用户必须能够将一段代码剪切/粘贴到他/她的网页中,以便'ajax in'他们已经配置的表单.

因此,Form模型的'embed-snippet'属性应该是只读的.当用户对表单进行更改并重新保存记录时,我不希望将代码段字段的内容发送回服务器.

我考虑过的一些方法:

  • 修改序列化程序以检查此特定属性,并在将其发送到后端之前将其从有效内容中删除
  • 将'embed-snippet'字段转换为与Form模型有关系的单独模型,然后以某种方式将其从保存中排除
  • 创建新的Ember Data属性类型

理想情况下,有一种更好的方法来处理这个问题.

就像是:

'DS.attr('string', { readOnly: true })
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,确保此字段的内容不会被发送回服务器的最佳方法是什么?

ember.js ember-data jsonapi-resources

15
推荐指数
2
解决办法
4154
查看次数

如何在rails和ember中集成Websockets和JSON API资源

有没有办法集成JSONAPI :: Resources gem来通过websockets将所有数据集中到ember?

还希望能够将数据从ember推送到rails并让jsonapi资源选择它并像常规http请求一样处理.

谢谢.

ruby-on-rails ember-data jsonapi-resources

6
推荐指数
0
解决办法
167
查看次数

JSON API筛选器包含的资源

问题是关于JSON API规范以及请求的正确处理方式(我正在使用ruby on rails和json api resources gem,但这还是一个普遍的问题,我知道如何实现它,我只想遵循JSON的规则API位于:http : //jsonapi.org/format/

情况一:

  • 我想要所有架子
  • 我想把那些书架上的所有书都包括在内
  • 在这种情况下,我应该使用的get是: www.library.com/shelves?include=books

情况2:

  • 我想获取所有书籍,但仅获取标记为未读的书籍

  • 我应该使用的get是: www.library.com/books?filter[unread]=true

设计包含未读书籍的所有书架的要求的正确方法是什么?

想不通这个

www.library.com/shelves?include=books&filter[books.unread]=true

www.library.com/shelves?include=unread_books?<-必须指定其他资源,即未读的书

www.library.com/shelves?filter[books.unread]=true

最正确的方法是什么?

编辑

与我的技术负责人和其他一些程序员交谈后,在这种情况下,最优先选择第一个选项

json json-api jsonapi-resources

5
推荐指数
1
解决办法
5732
查看次数

使用邮递员发送json api对象

我正在使用JSONAPI规范http://jsonapi.org/format/#status

我有以下数据,

{
  "data": 
    {
    "type": "tag",
    "id": "1",
    "attributes": {
        "name": "Test"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如何使用postman chrome扩展程序向终点发送帖子请求?

我正打算打电话,但我无法得到参数.

OBS.我已将Content-Type设置为application/vnd.api+json

谢谢 !

有效的HTML

json json-api jsonapi-resources jsonapiframework

5
推荐指数
1
解决办法
8363
查看次数

JSON API用于非资源响应

目前,我正在研究新产品,并为公共和内部需求制作REST API。我从{json:api}规范开始,对它感到非常满意,直到遇到一些无法找到答案的问题。

根据JSON API规范,每个资源都必须包含id

http://jsonapi.org/format/

每个资源对象必须包含一个id成员和一个type成员。id和type成员的值必须是字符串。

在很多情况下都可以,但不是全部。

我们的大多数端点都是关于“资源”的

如果我要收集“东西”(http://example.com/things

{
  "data": [{
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "first"
    },
    "links": {
      "self": "http://example.com/things/1"
    }
  }, {
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "second"
    },
    "links": {
      "self": "http://example.com/things/2"
    }
  }]
}
Run Code Online (Sandbox Code Playgroud)

如果我只要求一个“物”资源(http://example.com/things/1

{
  "data": {
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "first"
    },
    "links": {
      "self": "http://example.com/things/1"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是如何处理与资源无关且没有ID的终结点呢?

例如,在我们的应用程序中,存在一个端点http://example.com/stats,该端点应返回当前登录用户user的统计信息。喜欢 …

api rest json-api jsonapi-resources

5
推荐指数
1
解决办法
962
查看次数

jsonapi-resources自定义操作

我需要向jsonapi-resources控制器添加自定义操作。该操作只是创建一个新版本的先前存在的CollectorContent模型实例。我的实现(仅从此处复制):

routes.rb

jsonapi_resources :collector_contents do
  member do
    post :create_version
  end
end
Run Code Online (Sandbox Code Playgroud)

collector_contents_controller.rb

class CollectorContentsController < ApplicationController
  def create_version
    cc = CollectorContent.find(params[:id])
    cc_new_version = cc.create_version!
    render json: resource_serializer.serialize_to_hash(CollectorContentResource.new(cc_new_version, nil))
  end
end
Run Code Online (Sandbox Code Playgroud)

即使可行,似乎也不建议在控制器中添加新操作,但是我不明白如何使用操作处理器来实现用例。你能帮忙吗?

jsonapi-resources ruby-on-rails-5.2

5
推荐指数
0
解决办法
336
查看次数

如何在Rails中使用Ember Data 2和JSONAPI :: Resources来加载{json:api}记录?

我正在开发一个带有Rails后端的Ember应用程序,使用优秀的JSONAPI :: Resources gem来公开我的数据.

我想利用来从我的后端的记录store.findRecord,store.query等,而侧面加载一定的关系.JSONAPI :: Resources 支持 规范的这一部分,但我无法弄清楚如何使Ember Data包含?include=...请求URL中的参数.

如何指示Ember Data(2.2.0)在获取资源时要求后端包含关系?

ember.js ember-data json-api jsonapi-resources

3
推荐指数
1
解决办法
2196
查看次数

Laravel API 资源:如何返回无限嵌套的类别数组及其子项?

我使用 Laravel 6.x,以下是我的响应 JSON。

{
    "data": [
        {
            "id": 1,
            "name": "quam",
            "parent_id": 0
        },
        {
            "id": 2,
            "name": "quia",
            "parent_id": 1
        },
        {
            "id": 3,
            "name": "beatae",
            "parent_id": 1
        },
        {
            "id": 4,
            "name": "aut",
            "parent_id": 2
        },
        {
            "id": 5,
            "name": "provident",
            "parent_id": 0
        },
        {
            "id": 6,
            "name": "voluptate",
            "parent_id": 0
        },
        {
            "id": 7,
            "name": "vel",
            "parent_id": 2
        },
        {
            "id": 8,
            "name": "sed",
            "parent_id": 3
        },
        {
            "id": 9,
            "name": "voluptates",
            "parent_id": 0
        },
        { …
Run Code Online (Sandbox Code Playgroud)

php api laravel jsonapi-resources laravel-6

3
推荐指数
1
解决办法
4430
查看次数