Search code examples
restyaws

Yaws and PUT requests


I just started working with Yaws to try to create some simple RESTful web services, however I ran into an unexpected issue: I can't seem to access my data when I do a PUT request. When I try to use the yaws_api:parse_post function, I get the following error:

ERROR: Can't parse post body for 'PUT' requests: URL: ...

I wrote out the entire request and everything looks identical, so I'm very confused. Am I doing something wrong? GETs and POSTs work properly. In fact, the only difference between how I handle POSTs and PUTs right now is just what I display for each as right now I'm just writing test code to show success.

Thanks in advance.


Solution

  • I also find it weird that there's no equivalent of parse_post/1 for non-POST HTTP methods in the Yaws API.

    In any case, I simply use parse_query/1 for PUTs. Given a PUT request with param1=abc, param2=def:

    index(Args) ->
      case yaws_arg:method(Args) of
      'PUT' ->
        Parsed = yaws_api:parse_query(Args),
        io:format("PUT PARAMS=~p", [Parsed]),
        ....
      'POST' ->
        ....
    

    the output is:

    PUT PARAMS=[{"param1","abc"}, {"param2","def"}}]
    

    (The above example is in a Erlyweb controller.)