JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Incorrect `links` URL

Open
#1,076 1 comment 5 reactions 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

We need to omit the api out of the links URLs (eg: http://localhost:3001/api/v3/people). Our valid URL should look like this: http://localhost:3001/v3/people.

Here's a sample of how our routes.rb file is built:

Our routes.rb:

Rails.application.routes.draw do
  scope module: :api do
    namespace :v3 do
      jsonapi_resources :people
      jsonapi_resources :providers
    end
  end
end

According to the rake routes task on our person model:

v3_people GET       /v3/people(.:format)       api/v3/people#index
          POST      /v3/people(.:format)       api/v3/people#create
v3_person GET       /v3/people/:id(.:format)   api/v3/people#show
          PATCH     /v3/people/:id(.:format)   api/v3/people#update
          PUT       /v3/people/:id(.:format)   api/v3/people#update
          DELETE    /v3/people/:id(.:format)   api/v3/people#destroy

But the response output looks like this:

{
    "data": {
        "id": "1",
        "type": "people",
        "links": {
            "self": "http://localhost:3001/api/v3/people/1"
        },
        "attributes": {
            "full-name": "Chad Taylor",
            "first-name": "Chad",
            "last-name": "Taylor",
            "uuid": "dab4e5e6-ba50-42b4-9633-50a952d2e811"
        },
        "relationships": {
            "providers": {
                "links": {
                    "self": "http://localhost:3001/api/v3/people/1/relationships/providers",
                    "related": "http://localhost:3001/api/v3/people/1/providers"
                }
            }
        }
    }
}

If we can get the /api omitted from the links, all will be golden.

Thanks in advance.

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 the routes.rb example and the resource link generation for the person model. Reproduce the response showing /api/v3 URLs and trace how those links are assembled relative to the /v3 routes. Done means resource and relationship links omit the /api prefix while still resolving to the declared routes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.