0

If I have a REST API that accepts request like so,

/myuri/controller/action/firstname/johnny/lastname/quest

and I have a form that via Ajax posts to the backend PHP page, how can I submit my form's information without violating REST?

If I use .serialize for my form or use post like so,

http://api.jquery.com/jQuery.post/

$.post( "test.php", $( "#testform" ).serialize() );

or,

$.post( "test.php", { name: "John", time: "2pm" } );

isn't that keeping me from the format of my URI in the REST fashion, so my Ajax function has the url property looking like a REST URI?

How do I keep my URI in the REST fashion and be able to send data from a form to the backend pages?

EDIT: Are my assumptions about what a REST URI should be wrong here?

Querystring in REST Resource url

Community
  • 1
  • 1
johnny
  • 19,272
  • 52
  • 157
  • 259
  • Use `$.get` so the parameters will be put in the URL, and then use a rewrite rule that translates query parameters into URL components. – Barmar Jun 01 '15 at 21:08
  • @Barmar Thanks. I seem to be going round and round on this because some REST I see with a querystring, some do not, and it looks like the data: property of Ajax was made solely for the ?querystring in mind and that all the rewrites, are "hacky." Am I reading too much into what REST URIs should look like? – johnny Jun 01 '15 at 21:12
  • I don't use REST much. This site seems to agree with your expectation about RESTful URIs: http://blog.2partsmagic.com/restful-uri-design/ – Barmar Jun 01 '15 at 21:16

0 Answers0