JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Namespaced (with custom path option) and scoped routes support

Open
#257 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

My API endpoints are defined like that:

namespace :api, path: '' do
  scope ':customer' do
    api_version(module: 'V1', header: { ... }) do # versionist gem
      jsonapi_resources :users
    end
  end
end

This ends up with routes looking like:
/:customer/users/:id
but JR returns self links like:
/api/v1/users/:id

I managed to fixing that by monkey-patching JSONAPI::ResourceSerializer with:

module JSONAPI
  class ResourceSerializer
    def formatted_module_path(source)
      "#{currrent_customer}/"
    end
  end
end

but it's less than ideal. It would be nice to have a proper support for custom routes.

It could be fixed by #159 maybe.

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with JSONAPI::ResourceSerializer and its formatted_module_path method, which the issue identifies as the current workaround. Review the custom namespace and scope routes in the example and issue #159, then verify that generated self links match the routed /:customer/users/:id path without monkey-patching.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.