Skip to content

Inconsistent userId type in POST vs GET response #216

@Tania2607

Description

@Tania2607

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions