How to build postman request for Rails POST method

前端 未结 3 1621
暗喜
暗喜 2021-01-02 09:55

No matter how I format the raw portion of this request, I cannot avoid the parsing error below.

I have a Rails API with a create method that passes the spec, to illu

3条回答
  •  攒了一身酷
    2021-01-02 10:08

    Single quotes (') are not actually the legal string delimiter in JSON: a string must be enclosed in double quotes ("). You can get away with it in the browser, since they are string delimiters in javascript. You can easily replicate this in an irb session

    JSON.parse(%q[{'foo': 'bar'}]) #=> raises JSON::ParserError
    JSON.parse(%q[{"foo": "bar"}]) #=> ok
    

    In addition, given your spec you should be using the second form i.e.

    {
      "power_up": {
        "name": "foo",
        "description": "bar"
       }
    }
    

提交回复
热议问题