-
-
Notifications
You must be signed in to change notification settings - Fork 592
Description
There is a type inconsistency in the userId field of the posts endpoint in JSONPlaceholder.
-
When I send a GET request to /posts/1, userId is returned as an integer:
Response:
{
"userId": 1,
"id": 1,
"title": "...",
"body": "..."
} -
But when I send a POST request to /posts with userId=1, userId is returned as a string:
Response:
{
"body": "B",
"title": "A",
"userId": "1",
"id": 101
}
This inconsistency causes issues in typed languages like Swift or TypeScript where the model expects userId to be an Int.
Example Swift model that fails:
struct Post: Codable {
let id: Int?
let userId: Int
let title: String
let body: String
}
Suggested fix: Ensure the userId is always returned as an integer in all responses, including POST, to keep the API behavior consistent.
Thank you for the amazing tool!