Skip to content
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

userId is Int when GET, but String when get result after POST #182

Open
elijah-rappaport opened this issue Mar 23, 2022 · 0 comments
Open

Comments

@elijah-rappaport
Copy link

elijah-rappaport commented Mar 23, 2022

There is a discrepancy in the type for userId. This appears to be an issue on all the endpoints. Below is an illustration of the issue on the "posts" endpoint.

When I GET a post, userId is an Int, as you see here...

GET 'https://jsonplaceholder.typicode.com/posts/1'
curl "https://jsonplaceholder.typicode.com/posts/1"
200 'https://jsonplaceholder.typicode.com/posts/1'
{
"userId": 1, <==== Int
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

When I get the result after POST a new post, userId is a String, as you see here...

POST 'https://jsonplaceholder.typicode.com/posts'
Content-Type : application/x-www-form-urlencoded
HttpBody : body=B&title=A&userId=1&id=-1
curl "https://jsonplaceholder.typicode.com/posts"
-X POST
-H 'Content-Type: application/x-www-form-urlencoded'
-d 'body=B&title=A&userId=1&id=-1'
201 'https://jsonplaceholder.typicode.com/posts'
{
"body": "B",
"title": "A",
"userId": "1", <==== String
"id": 101
}

This issue causes errors in my code when trying to decode or encode using the same struct
struct Post: Codable {
let id: Int?
let userId: Int <== this will cause error when trying to convert the json received back from a POST, as I'm expecting an Int but getting a String
var title: String
var body: String
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant