cerebris / jsonapi-resources

A resource-focused Rails library for developing JSON:API compliant servers.
http://jsonapi-resources.com
MIT License
2.32k stars 529 forks source link

Incorrect `links` URL #1076

Open chadwtaylor opened 7 years ago

chadwtaylor commented 7 years ago

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.

zion commented 11 months ago

@chadwtaylor Just wondering if you ever found a work around for this? I have the same issue.