Questions tagged [jsonapi-resources]

JSONAPI-Resources is a Ruby library to write clients and servers for the JSONAPI standard.

JSONAPI-Resources is a Ruby library to write clients and servers for the JSON API standard.

JSONAPI may be regarded as a set of best practices for writing JSON-based APIs, or as an actual standard. JR's github page serves as its home page and the author's blog contains some introductory postings.

111 questions
3
votes
0 answers

Rails Globalize Gem + JSON Resources Gem

I have a project where I need to use internacionalization for table fields and to provide a jsonapi. To accomplish this I'm using the Globalize Gem and the JSON API Gem. This is the code for a simple model called category: class Category <…
Tiago
  • 673
  • 1
  • 8
  • 24
3
votes
1 answer

JSONAPI best way for responding a non-resource data like a access token with jsonapi-resources

I'm implementing this API and the first thing I did was the login with access token. I'm using the jsonapi-resources gem https://github.com/cerebris/jsonapi-resources I have two problems now. I want to return a user AND the generated access token in…
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120
3
votes
2 answers

creating singular resources in jsonapi-resources

Using the jsonapi-resources gem (and Rails 4), I'm attempting to create a singular (or singleton) resource (not supplying the id on the url for the standard show, update and delete requests), in my case for a profile of the current (logged in) user,…
IanI
  • 370
  • 3
  • 9
3
votes
2 answers

How to sideload {json:api} records with Ember Data 2 and JSONAPI::Resources in Rails?

I'm developing an Ember app with a Rails backend, using the excellent JSONAPI::Resources gem to expose my data. I'd like to fetch records from my the backend using store.findRecord, store.query, etc. while sideloading certain relationships.…
Max Wallace
  • 3,609
  • 31
  • 42
3
votes
3 answers

Is there a way to manually serialize a collection?

I'd like to manually serialize a collection for testing purposes. I tried this: JSONAPI::ResourceSerializer.new(PostResource). serialize_to_hash(PostResource.new(Post.all)) This doesn't work. It appears you can only serialize a single resource…
3
votes
1 answer

How to do `has_one: model, through: join_model` in JSONAPI::Resource

What's the preferred way to do has_one :model, through: join_model in a model resource? Usually JSONAPI::Resource expects model_id column on the table/model who owns the association. That does not exist if a join table/model is used.
Yaw Boakye
  • 10,352
  • 1
  • 17
  • 25
2
votes
1 answer

Running stand-alone Rails script

I'm submitting a bug report to jsonapi-resources. Their issue template asks that I create a MCVE using their template. This looks like a self-contained script for a rails-based project. I've only ever run similar code as an actual rails project with…
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
2
votes
1 answer

JSONAPI-Resources: NameError could not find resource

I am using JSONAPI-Resourcs an API project. When I try and namespace it I hit an error where the server won't start. Digging in deeper when I run bin/rails zeitwerk:check I get the following error: NameError: JSONAPI: Could not find resource…
noobmaster69
  • 2,985
  • 3
  • 27
  • 44
2
votes
0 answers

JSONAPI Resources: undefined method serialize_to_hash

I am using the gem jsonapi-resources 0.10.5. This is my resource: class ProjectResource < JSONAPI::Resource attributes :name end and this is my controller: class V2::ProjectController < V2::BaseController def index project =…
soltex
  • 2,993
  • 1
  • 18
  • 29
2
votes
0 answers

How to create requests params for json api resources in requests tests?

I'm creating a API with Rails 6 and JSON API Resource in order to learn more. I got stuck with requests tests. What I'm doing for now is using the gem json_matchers to test the response of my endpoint, but my real problem is to build the body of…
Pedro Paiva
  • 721
  • 11
  • 17
2
votes
0 answers

Laravel API Resources to transform models into POST request data

I'm using Laravel Resources to transform both my own API responses and the responses I receive from a third party as described in this article. I also have some of my models I would like to transform into JSON to post to the third party API. For all…
RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75
2
votes
0 answers

Ruby on rails: Arel tables join returns wrong number of arguments (given 1, expected 0)

In ruby on rails when joining the two arel tables throws error "wrong number of arguments (given 1, expected 0). Below is the sample tab_a = TableA.arel_table, tab_b = TableB.arel_table query =…
2
votes
2 answers

Rails 5 API integration tests don't work with jsonapi-resources

I can't test POST requests against my jsonapi-resources Rails 5.1 API. Rails does not seem to allow me to customize request content types, or is doing it wrong. jsonapi-resources version 0.9.0, edge Rails (I think it's 5.2 beta2) So, this…
2
votes
0 answers

jsonapi-resources cross versions relationships

How can I add a new version of a resource without duplicating his related resources and controllers? Lets say I have an API described by the following routing: namespace :api do namespace :v1 do jsonapi_resources :contacts …
kirlev
  • 680
  • 1
  • 7
  • 17
2
votes
1 answer

Error in Access-Control-Allow-Origin when Angular request to Rails

I'm using Angular 2 to make an API(rails) request. When I make the http request through angular, I get the following error: XMLHttpRequest cannot load https://api-url. Response to preflight request doesn't pass access control check: No…