json-api

API formation for side loading only required associated data to ember data

扶醉桌前 提交于 2019-12-26 00:49:17
问题 Please check my previous question EMBER JS - Fetch associated model data from back-end only when required Related to the above question I need help on API formation in ruby on rails(JSON format: jsonapi.org) how to form the API for sideloading only students.records and link with data already available in ember-data store (school and students) 回答1: based on the comments in the other question, I think you're wanting something like GET /api/students?include=records But you need that filtered to

API formation for side loading only required associated data to ember data

不想你离开。 提交于 2019-12-26 00:49:05
问题 Please check my previous question EMBER JS - Fetch associated model data from back-end only when required Related to the above question I need help on API formation in ruby on rails(JSON format: jsonapi.org) how to form the API for sideloading only students.records and link with data already available in ember-data store (school and students) 回答1: based on the comments in the other question, I think you're wanting something like GET /api/students?include=records But you need that filtered to

Active Model Serializers data attributes from associations are not loading

不想你离开。 提交于 2019-12-25 06:57:59
问题 I am trying to load the association as follows: This is my controller which is trying to render the json. #app/controllers/store/products_controller.rb def customize @option_types = OptionType.all respond_to do |format| format.json { render :json => @option_types} end end This is the serializer for above object #app/serializers/option_type_serializer.rb class OptionTypeSerializer < ActiveModel::Serializer attributes :id, :key, :customizable, :name has_many :option_values end option_value

How do I create relationship from json column data on same table?

戏子无情 提交于 2019-12-24 23:33:06
问题 I have something like the following table (tablename = applications ): | id | applicants | | ------------- | ------------- | | uuid-123-abc | [{'first_name':'Dave'},{'first_name':'Steve'}] | I need to be able to create a relationship for it so I can just go: $application->applicants and (in this example) get a collection with two Applicant models. I'm assuming I'll need an Applicant model class somewhere. But I'm not even sure if this can be done because there is no applicant table. I was

Get kaminari pagination links in the JSON generated by the active model serializer

泪湿孤枕 提交于 2019-12-24 16:33:54
问题 I am trying to convert @admins to JSON using the AdminSerializer #app/serializers/admin_serializer.rb class AdminSerializer < ActiveModel::Serializer attributes :id, :email, :access_locked? end where Admins is>> @admins = @search.result(:distinct => true).page(params[:page][:number]).per(10) and @search = Admin.search(params[:q]) When I execute this command>> ActiveModel::SerializableResource.new(@admins.to_a).as_json I do get the desired JSON, but the pagination links are missing from the

HATEOAS and forms driven by the API

半城伤御伤魂 提交于 2019-12-23 12:26:54
问题 I'm trying to apply HATEOAS to the existing application and I'm having trouble with modeling a form inputs that would be driven by the API response. The app is allowing to search & book connections between two places. First endpoint allows for searching the connections GET /connections?from={lat,lon}&to={lat,lon}&departure={dateTime} and returns following payload (response body). [ { "id": "aaa", "carrier": "Fast Bus", "price": 3.20, "departure": "2019-04-05T12:30" }, { "id": "bbb", "carrier"

Post to Rails from Emberjs using JSONAPI adapter, Rails not seeing the params

断了今生、忘了曾经 提交于 2019-12-23 12:21:07
问题 I am trying to save a message model in Emberjs. I am using the JSONAPIAdapter and JSONAPISerilzier. My post to rails hits the right controller and action as a post, but if I look inside with Pry, the data attributes are not there. My payload: {"data":{"attributes":{"body":"Why","user_id":"17"},"relationships":{"user":{"data":null},"conversation":{"data":null}},"type":"messages"}} Content-Type:application/vnd.api+json Rails params in the Rails console: {"format"=>"json", "controller"=>"api/v1

Action Cables, nested JSON attributes and JSONAPI

喜夏-厌秋 提交于 2019-12-22 15:54:31
问题 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'),

Do I need Oauth2 For my Web Apps API

元气小坏坏 提交于 2019-12-19 07:49:58
问题 I am trying to wrap my brain around building an express.js / node.js based REST API. I have a couple of questions... Do I NEED token based / oauth 1 or 2 security for my api if I'm only concerned about a web application right now (not necessarily phone apps) Are there any resources to learn how to build this from scratch? I've read literally the first 3 pages of googling "rest api with oauth2 authentication express.js" and i'm still not grasping it. 回答1: Its good that you want to do a REST

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

会有一股神秘感。 提交于 2019-12-19 04:50:18
问题 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