-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PUT saves the updated item with an id that has been converted to string #396
Comments
Hi @kolbeypruitt, Thank you for the report, that's unexpected. What's the version of JSON Server you're using? npm install -g json-server@next |
I have encountered the same, with and without using a middleware.
I'll try to rollback on an older version to fix this temporarily. |
So v0.8.23 does not suffer these issues. Something else I've encountered, it looks like you're saving the ID on PUT again from the URL and not from the object which is being passed as payload? I guess that's where the ID as a String comes from. |
This issue exists with PATCH as well: This was using: then downgraded to v0.8.23 which fixed the issue. |
So there is 0.9.1 out, anyone tested this? |
This issue is still present in the version 0.9.2, at least for PATCH requests. |
Well, would love to update, but with this still being present, I'll have to run on v0.8.23 then. |
The first thing would need to have a failing test: Does someone want to make a PR? |
Actually, I think I understand better why we're getting this. If the content type is $.ajax('http://localhost:3000/posts/1', {
method: 'PUT',
data: {
id: 1,
title: 'foo',
body: 'bar',
userId: 1
}
}).then(function(data) {
console.log(data);
});
// {id: "1", title: "foo", body: "bar", userId: "1"} On the other side, if it's sent as fetch('http://localhost:3000/posts/1', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: 1,
title: 'foo',
body: 'bar',
userId: 1
})
}).then(function(response) {
return response.json()
}).then(function(obj) {
console.log(obj)
}); |
Fixed on For the test, I found why it wasn't detecting the issue. Deep equal comparison was used instead of the strict one (i.e. |
I have encountered this issue too. Cannot waiting for the new release... A great project, it saves a lot of time for us. |
It's released ( |
You can't specify, but JSON Server figures out "automatically" somehow. For example, if you have a {
"posts": []
} or {
"posts": [{ "id": 1 }]
} The next post created will be
On the other side, if you create: {
"posts": [{ "id": "1" }]
} When you create a new post, But I don't think, or at least haven't seen a case, where it affects the front-end to have That said, if you want, you can still intercept the response and modify router.render = function (req, res) {
var data = res.locals.data
data.id = data.id.toString()
res.jsonp(data)
} |
In 0.12.1 I can still reproduce this issue but on NESTED objects.
If I do a POST on /fruits/1/recipe, the recipe gets correctly an integer ID, but fruitId is a string. |
This is happening for me on nested objects as well.. |
Still a problem for me today in |
Threat the request param as integer closes typicode#925, closes typicode#396
Threat the request param as integer closes typicode#925, closes typicode#396
@typicode there is ready fix for this on nested, can you merg? |
switching to v0.8.23 works for me. Thanks. |
becomes
The text was updated successfully, but these errors were encountered: