Json-server: Nested Resource foreign key parsed as string

Created on 2 Mar 2019  Â·  4Comments  Â·  Source: typicode/json-server

When doing a POST request to create a new nested resource, its foreign key is parsed as string, as opposed to integer. This causes the parent to not recognize its child resource.

For example

POST /posts/1/images

BODY
{
    url: ‘some-url’
}

would yield a response

{
    url: ‘some-url’,
    postId: “1”,
    id: 1
}

So, when doing a GET request
GET /posts/1?_embed=images, the response is as follows

{
    id: 1,
    ...,
    images : [],
}

Essentially, the post doesn’t recognize the image attached to it, because the foreign key is parsed as string.

Manually changing the foreign key into integer data type will work.

Any suggestion? Is this how it’s supposed to work?

Some existing comments that I found

All 4 comments

Can this one be merged? We suffer from the same problem!

Same here. It's kind of a blocker when you are trying to mock POST methods.

Hoping this could get merged as well!

Would be great if we could get this merged.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bahmutov picture bahmutov  Â·  3Comments

dotmobo picture dotmobo  Â·  4Comments

strom picture strom  Â·  4Comments

Rutvik17 picture Rutvik17  Â·  4Comments

pantchox picture pantchox  Â·  3Comments