LostKobrakai Posted September 22, 2014 Share Posted September 22, 2014 Hi, I currently trying to get my head around creating more dynamic pages. I've watched a few tutorials and read some stuff about api's correspondig to all the frontend technics. Now most of the api's in the tutorials use the http request methods to distinguish between the four crud actions create, read, update and delete. I'm wondering are there any differences in these requests other than you being able to read the type with php? I'm considering using urlSegments, rather than different request-types, because I don't really like the idea of reusing a request type which was implemented for other usage. Are there any real differences between those methods? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 22, 2014 Share Posted September 22, 2014 I'm not sure I fully understand what you're up-to, but using urlSegments to work with AJAX is in my opinion a good thing, because urlSegments are fully cache-able. You could on template level, output the data corresponding to the urlSegments. On a local project I do store all the json & markup results in a JSON object after the data has been pulled in, the next time the data is requested, the data is pulled from the JSON object so no extra request has to be made to the server. If used in combination with pagecache, it's real quick offtopic: I've used History.js and I love it. Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 22, 2014 Author Share Posted September 22, 2014 I'll maybe add some dynamic updating to the otherwise static pages of my current project. My question is only, if there's some difference between this: switch($_SERVER['REQUEST_METHOD']){ case "GET": doStuff(); break; case "PUT": doStuff(); break; […] } $.ajax({type: "PUT", url: "/api/"}); versus switch($input->urlSegment1){ case "read": doStuff(); break; case "update": doStuff(); break; […] } $.ajax({type: "POST", url: "/api/update"}); Link to comment Share on other sites More sharing options...
Recommended Posts