json-api

JSON API response and ember model names

試著忘記壹切 提交于 2019-12-10 13:41:10
问题 A quick question about the JSON API response key "type" matching up with an Ember model name. If I have a model, say "models/photo.js" and I have a route like "/photos", my JSON API response looks like this { data: [{ id: "298486374", type: "photos", attributes: { name: "photo_name_1.png", description: "A photo!" } },{ id: "298434523", type: "photos", attributes: { name: "photo_name_2.png", description: "Another photo!" } }] } I'm under the assumption that my model name should be singular but

How to generate JSON-API data attribute vs results attribute in Django Rest Framework JSON API?

三世轮回 提交于 2019-12-10 13:40:46
问题 I have a django 1.9.2 project using Django Rest Framework JSON API: https://github.com/django-json-api/django-rest-framework-json-api: My viewset looks like this: class QuestionViewSet(viewsets.ReadOnlyModelViewSet): """ API endpoint that allows questions and answers to be read. """ resource_name = 'questions' queryset = Question.objects.all() serializer_class = QuestionSerializer renderers = renderers.JSONRenderer parsers = parsers.JSONParser Typical response looks like this: {"links": {

Why is the HTTP location header only set for POST requests/201 (Created) responses?

我只是一个虾纸丫 提交于 2019-12-07 09:11:52
问题 Ignoring 3xx responses for a moment, I wonder why the HTTP location header is only used in conjunction with POST requests/201 (Created) responses. From the RFC 2616 spec: For 201 (Created) responses, the Location is that of the new resource which was created by the request. This is a widely supported behavior, but why shouldn't it be used with other HTTP methods? Take the JSON API spec as an example: It defines a self referencing link for the current resource inside the JSON payload (not

Action Cables, nested JSON attributes and JSONAPI

眉间皱痕 提交于 2019-12-06 09:33:25
I have a fairly specific problem that I was hoping one of you really intelligent folk might know a solution for (or even a workaround at this stage) Specifically, I'm dealing with action cables, nested JSON, and the JSONAPI . I have an asset model, which has some attributes like name , desc etc. but it also has an attribute called state which is a complex nested JSON object. // app/models/asset.js export default DS.Model.extend({ // Attributes name: DS.attr('string'), desc: DS.attr('string'), state: DS.attr(), lastSeen: DS.attr('date'), }); When anything on the asset changes in the backend, it

Why is the HTTP location header only set for POST requests/201 (Created) responses?

青春壹個敷衍的年華 提交于 2019-12-05 12:44:59
Ignoring 3xx responses for a moment, I wonder why the HTTP location header is only used in conjunction with POST requests/201 (Created) responses. From the RFC 2616 spec : For 201 (Created) responses, the Location is that of the new resource which was created by the request. This is a widely supported behavior, but why shouldn't it be used with other HTTP methods? Take the JSON API spec as an example: It defines a self referencing link for the current resource inside the JSON payload ( not uncommon for RESTful APIs ). This link is included in every payload. The spec says that you MUST include

ember js get meta informations from json

可紊 提交于 2019-12-04 04:28:32
问题 i have a json data from my server: { "post": { "id": 1, "title": "Progressive Enhancement is Dead", "comments": ["1", "2"], "links": { "user": "/people/tomdale" } }, "meta": { "total": 100 } } look exactly like the documentation (https://guides.emberjs.com/v2.5.0/models/handling-metadata/) i try to get the meta object with no success export default Ember.Route.extend({ model() { var data = this.store.findAll('post'); data.then((result) => { let meta = result.get('meta'); console.log(meta); /

ember js get meta informations from json

冷暖自知 提交于 2019-12-02 00:07:47
i have a json data from my server: { "post": { "id": 1, "title": "Progressive Enhancement is Dead", "comments": ["1", "2"], "links": { "user": "/people/tomdale" } }, "meta": { "total": 100 } } look exactly like the documentation ( https://guides.emberjs.com/v2.5.0/models/handling-metadata/ ) i try to get the meta object with no success export default Ember.Route.extend({ model() { var data = this.store.findAll('post'); data.then((result) => { let meta = result.get('meta'); console.log(meta); //this return me undefined }) return data; } }); You are using findAll method and it does not support

How to access top level meta key from json-api server's 200 response when calling ember data's destroyRecord()

断了今生、忘了曾经 提交于 2019-12-01 20:10:52
问题 I'm working on an Ember app that is using Ember Data and the now default json-api adapter. According to the json-api spec (http://jsonapi.org/format/#crud-deleting) when deleting a record your server should return a 200 response if the deletion is successful and the server responds with just a top level meta key. My current server does just this and I'm trying to figure out how to access the data in the top level meta object when using Ember Data's model.destroyRecord() method. myModel

How to test Controller post :create of JSON api on rails using rspec?

こ雲淡風輕ζ 提交于 2019-12-01 01:21:57
I have been tearing my hair trying to make the test to pass. I have a JSON API that looks like this: { "data": [ { "id": "b99f8173-0492-457f-9de9-6c1d8d6832ed", "type": "manufacturer_organizations", "attributes": { "account_number": "random test 123" }, "relationships": { "organization": { "data": { "id": "fb20ddc9-a3ee-47c3-bdd2-f710541ff89c", "type": "organizations" } }, "manufacturer": { "data": { "id": "1", "type": "manufacturers" } } } },... I am trying to make a post :create test in rails. let!(:manufacturer_organization) {FactoryGirl.create(:manufacturer_organization)} let(:manufacturer

Handling errors with the (now default) Ember Data JSON-API adapter

二次信任 提交于 2019-11-27 03:58:41
I am using Ember 1.13.7 and Ember Data 1.13.8, which by default use the JSON-API standard to format the payloads sent to and received from the API. I would like to use Ember Data's built-in error handling in order to display red "error" form fields to the user. I have formatted my API error responses as per the JSON-API standard, e.g. {"errors":[ { "title":"The included.1.attributes.street name field is required.", "code":"API_ERR", "status":"400", } ]} and when I attempt to save my model the error callback is being correctly executed. If I look within the Ember Inspector I can see that the