purescript-halogen-realworld icon indicating copy to clipboard operation
purescript-halogen-realworld copied to clipboard

update user and post comment request body differ from spec

Open jim108dev opened this issue 4 years ago • 5 comments

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.

jim108dev avatar Jan 30 '21 23:01 jim108dev

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?

jim108dev avatar Jan 31 '21 07:01 jim108dev

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.

thomashoneyman avatar Aug 10 '21 22:08 thomashoneyman

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?

nilp0inter avatar Aug 25 '21 18:08 nilp0inter

@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

thomashoneyman avatar Aug 27 '21 00:08 thomashoneyman

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.

garyb avatar Aug 27 '21 01:08 garyb

This was fixed in #116

thomashoneyman avatar Sep 19 '22 16:09 thomashoneyman