Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plain ruby examples #22

Open
alexandru-calinoiu opened this issue May 26, 2020 · 1 comment
Open

Plain ruby examples #22

alexandru-calinoiu opened this issue May 26, 2020 · 1 comment
Labels
good first issue Good for newcomers
Milestone

Comments

@alexandru-calinoiu
Copy link

Expected Behavior

Will like the readme to have plain ruby examples

Actual Behavior

The readme looks very rails oriented

Steps to Reproduce the Problem

None

Specifications

  • Version:
  • Ruby version:
@stas stas added the good first issue Good for newcomers label May 26, 2020
@stas stas added this to the v1.8 milestone Sep 1, 2021
@code-bunny
Copy link

code-bunny commented Aug 2, 2023

We've been enjoying this gem for Rails controllers but now moving to Grape API's it would be smashing if there was an easy to use interface. So a wee plus one for this.

In general for Grape it is as easy as not having the initialiser to fire it and instead including the filters in your API as follows

class API < Grape::API
  API_BASE_URL = "http://localhost:9001"

  content_type :jsonapi, "application/vnd.api+json"
  default_format :jsonapi
  format :jsonapi

  helpers JSONAPI::Pagination, JSONAPI::Filtering

  resources :users do
    get do
      allowed = [:id, :email]
      filtered = jsonapi_filter(User.includes(:documents, :addresses).all, allowed)
      users = jsonapi_paginate(filtered.result)

      pagination_meta  = jsonapi_pagination_meta(users)
      pagination_links = jsonapi_pagination(users)

      if pagination_meta.present?
        options[:meta]  = { pagination: pagination_meta }
        options[:links] = pagination_links
      end

      UserSerializer.new(users, options).serializable_hash
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants