<p>We are trying to implement a REST API for an application we have now. We want to expose read/write capabilities for various resources using the REST API. How do we implement the "form" part of this? I get how to expose "read" of our data by creating RESTful URLs that essentially function as method calls and return the data:</p>

<pre><code>GET /restapi/myobject?param=object-id-maybe
</code></pre>

<p>...and an XML document representing some data structure is returned. Fine.</p>

<p>But, normally, in a web application, an "edit" would involve two requests: one to load the current version of the resources and populate the form with that data, and one to post the modified data back. </p>

<p>But I don't get how you would do the same thing with HTTP methods that REST is sort of mapped to. It's a PUT, right? Can someone explain this?</p>

<p>(Additional consideration: The UI would be primarily done with AJAX)</p>

<p>--
Update: That definitely helps. But, I am still a bit confused about the server side? Obviously, I am not simply dealing with files here. On the server, the code that answers the requests should be filtering the request method to determine what to do with it? Is that the "switch" between reads and writes?</p>

[{'answer_id': 46014, 'author': 'Matt Sheppard', 'author_id': 797, 'author_profile': 'https://Stackoverflow.com/users/797', 'pm_score': 0, 'selected': False, 'text': '<p>The load should just be a normal GET request, and the saving of new data should be a POST to the URL which currently has the data...</p>\n\n<p>For example, load the current data from <a href="http://www.example.com/record/matt-s-example" rel="nofollow noreferrer">http://www.example.com/record/matt-s-example</a> and then, change the data, and POST back to the same URL with the new data.</p>\n\n<p>A PUT request could be used when creating a new record (i.e. PUT the data at a URL which doesn\'t currently exist), but in practice just POSTing is probably a better approach to get started with.</p>\n'}, {'answer_id': 46015, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 3, 'selected': True, 'text': "<p>If you're submitting the data via plain HTML, you're restricted to doing a POST based form. The URI that the POST request is sent to <strong>should not</strong> be the URI for the resource being modified. You should either POST to a collection resource that ADDs a newly created resource each time (with the URI for the new resource in the <em>Location</em> header and a <strong>202</strong> status code) or POST to an updater resource that updates a resource with a supplied URI in the request's content (or custom header).</p>\n\n<p>If you're using an XmlHttpRequest object, you can set the method to PUT and submit the data to the resource's URI. This can also work with empty forms if the server supplies a valid URI for the yet-nonexistent resource. The first PUT would create the resource (returning <strong>202</strong>). Subsequent PUTs will either do nothing if it's the same data or modify the existing resource (in either case a <strong>200</strong> is returned unless an error occurs).</p>\n"}, {'answer_id': 46056, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 2, 'selected': False, 'text': '<p>I think you need to separate data services from web UI. When providing data services, a RESTful system is entirely appropriate, including the use of verbs that browsers can\'t support (like PUT and DELETE).</p>\n\n<p>When describing a UI, I think most people confuse "RESTful" with "nice, predictable URLs". I wouldn\'t be all that worried about a purely RESTful URL syntax when you\'re describing web UI.</p>\n'}, {'answer_id': 176639, 'author': 'Alexandros Marinos', 'author_id': 24461, 'author_profile': 'https://Stackoverflow.com/users/24461', 'pm_score': 4, 'selected': False, 'text': '<p>There are many different alternatives you can use. A good solution is provided at the <a href="http://microformats.org/wiki/rest/urls" rel="nofollow noreferrer">microformats wiki</a> and has also been referenced by the RESTful JSON crew. As close as you can get to a standard, really.</p>\n\n<pre><code> Operate on a Record\n\nGET /people/1\n    return the first record \nDELETE /people/1\n    destroy the first record \nPOST /people/1?_method=DELETE\n    alias for DELETE, to compensate for browser limitations \n\nGET /people/1/edit\n    return a form to edit the first record \nPUT /people/1\n    submit fields for updating the first record \nPOST /people/1?_method=PUT\n    alias for PUT, to compensate for browser limitations \n</code></pre>\n'}]
['https://Stackoverflow.com/questions/46004', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/577/']