JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

URL host name is not generated properly in self link with serializer

Open
#978 5 comments 0 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

I sometime use the serializer to render the reply from some API request like below.
In controller

    result = Hoge.find(1)
    resource = Object.const_get('HogeResource')
    serializer = JSONAPI::ResourceSerializer.new('HogeResource')
    body = serializer.serialize_to_hash(resource.new(result, nil))
    render json: body, status: 20

and the result is
http://localhost:3000/hoges/1

{
  "data": {
    "id": "1",
    "type": "hoges",
    "links": {
      "self": "/hoges/1"
    },
    "attributes": {

self should have the hostname like http://localhost:3000/amc/hoges/1

Any idea how to fix this?

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

Reproduce the controller example with JSONAPI::ResourceSerializer and inspect how it builds the resource's self link. Verify the serialized link includes the request hostname and the /amc path, then add or update coverage for the expected absolute URL.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.