Closed 4O4 closed 8 years ago
you need to add a Content-Type: application/json
header to the PUT request, to tell the server what format the data is in.. launch the mock example you linked to then run these two commands, you'll see the user record was updated:
$ curl http://127.0.0.1:8000/users/1 --header 'Content-Type: application/json' -X PUT --data-raw '{ "id": 1, "name": "cake" }' && echo
$ curl http://127.0.0.1:8000/users/1 && echo
i need to improve the documentation.. let me know if you have any more issues.
Well, yesterday I was testing with this header... but I double checked now and it works indeed. Must have done a typo in content-type or something. Thank you for your help!
As the title says. I thought that maybe I am doing something wrong, but then I took the examples from repository (https://github.com/75lb/local-web-server/tree/master/example/mock) and the same problem occurs. PUT request to /users/1 is in fact removing the user, because there is no ctx.request.body and POST request to /users adds object with just "id" property to the users array. It's the most useful feature of mocks for me and sadly it is not working.
I've googled a bit and the problem seems to be related to Koa bodyparser. Tried to fix it myself, but I don't have enough knowledge about Koa to understand what exactly is going wrong and why.