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

PUT request without stringify'ing body returns 500 #143

Open
BrennanAyers opened this issue Aug 11, 2020 · 0 comments
Open

PUT request without stringify'ing body returns 500 #143

BrennanAyers opened this issue Aug 11, 2020 · 0 comments

Comments

@BrennanAyers
Copy link

Steps to reproduce:

  • Note the lack of stringifying the body object
fetch('https://jsonplaceholder.typicode.com/posts/1', {
    method: 'PUT',
    body: {
      id: 1,
      title: 'foo',
      body: 'bar',
      userId: 1
    },
    headers: {
      "Content-type": "application/json; charset=UTF-8"
    }
  })
  .then(response => response.json())
  .then(json => console.log(json))

Expected response:

400 Bad Request

Actual response:

500 Internal Server Error

I believe it has something to do with the mismatch in the Content-Type and the input. If the Content-Type header is set to application/x-www-form-urlencoded, the response will return a 200, but with the following body:

{
  "[object Object]": "",
  "id": 1
}
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