purescript-halogen-realworld
purescript-halogen-realworld copied to clipboard
update user and post comment request body differ from spec
Hi! I have tried to add a comment. The frontend sends
{"body":"hello"}
According to https://github.com/gothinkster/realworld/tree/master/api it should be
POST /api/articles/:slug/comments
Example request body:
{
"comment": {
"body": "His name was my name too."
}
}
The same applies to update article.
Also, please correct me if I am wrong. The backend gives specific error messages
Errors and Status Codes
If a request fails any validations, expect a 422 and errors in the following format:
{
"errors":{
"body": [
"can't be empty"
]
}
}
I don't see any of these errors popping up. Does the frontend actually parse them?
Hi @jim108dev! Sorry for such a late response. It may be that I've diverged from the spec in this implementation, and that's a bug here that needs to be fixed. I can take a look at that, though I would also accept PRs that fixes these issues you've found.
I am working on a pull request trying to solve this issue. I managed to modify the post comment request and have it is working now 🎉
But I am stuck trying to fix the update user request. In the current implementation the update user request sent when editing the user profile sends unfilled fields with null
values. The backend I am using to test this is not happy with that encoding, instead it wants the missing fields to be absent in the JSON object. AFAIK, that encoding is not possible using the current purescript-codec-argonaut
library, but I maybe mistaken.
Any ideas on how this can be fixed?
@garyb I can’t quite remember how to do this — do you have any advice?
@nilp0inter it should be possible to do this by adjusting how Maybe values get encoded, but I’m not sure if there’s something built in off the top of my head
There's a PR to add it https://github.com/garyb/purescript-codec-argonaut/pull/31/files but it's unmerged... I did want to do something to make it more convenient - so that codecs can still be defined record-style - but every time I've started on it I get sidetracked by wanting to deal with constant values also, and haven't quite figured out a good way of making it all fit just yet.
This was fixed in #116