chkaufmann 17 Posted January 10, 2022 I'm about to build a REST API using a TIdHTTPServer. Now even in the latest version of Indy the command PATCH is not listed in THTTPCommandType. Is there a reason for that? Or should a just use PUT for all update requests? To be honest when I read in the internet about the differences for PUT, PATCH and POST there are no unique opinions. So maybe I just use POST do add items and PUT for any updates (partial and complete). Regards Christian Share this post Link to post
Der schöne Günther 316 Posted January 10, 2022 (edited) I never understood that either. In our code, it is handled like this: isPutOrPatch := (ARequestInfo.CommandType = THTTPCommandType.hcPUT) or ( (ARequestInfo.CommandType = THTTPCommandType.hcUnknown) and (ARequestInfo.Command = 'PATCH') ); As you can see, our REST server handles PUT and PATCH commands exactly the same. 1 hour ago, chkaufmann said: So maybe I just use POST do add items and PUT for any updates (partial and complete). That is absolutely legit. The important part is to make it known to your API consumers. Edited January 10, 2022 by Der schöne Günther Share this post Link to post
Remy Lebeau 1401 Posted January 10, 2022 (edited) 3 hours ago, chkaufmann said: I'm about to build a REST API using a TIdHTTPServer. Now even in the latest version of Indy the command PATCH is not listed in THTTPCommandType. Is there a reason for that? I imagine it is because PATCH is not in the official HTTP protocol RFCs, it is a non-official extension. But, since TIdHTTP supports PATCH, it makes sense that TIdHTTPServer should allow it, too. So I will consider adding it (https://github.com/IndySockets/Indy/issues/395). That being said, you can alternatively use the TIdHTTPRequestInfo.Command property instead, which is the original verb string before it is translated to the TIdHTTPRequestInfo.CommandType property. And because of that, I wonder if it would be better to just deprecate the TIdHTTPRequestInfo.CommandType property altogether? Quote Or should a just use PUT for all update requests? To be honest when I read in the internet about the differences for PUT, PATCH and POST there are no unique opinions. Because there is no official differentiation between them, so it is open to interpretation by implementations. Edited January 10, 2022 by Remy Lebeau Share this post Link to post
Remy Lebeau 1401 Posted January 16, 2022 On 1/10/2022 at 8:46 AM, Remy Lebeau said: But, since TIdHTTP supports PATCH, it makes sense that TIdHTTPServer should allow it, too. So I will consider adding it (https://github.com/IndySockets/Indy/issues/395). I have just now checked in an update for this. Share this post Link to post
Der schöne Günther 316 Posted January 17, 2022 So looking at #395 Adding hcPATCH to THTTPCommandType · IndySockets/Indy@4813ee0 (github.com) that means my code for determining isPutOrPatch will now fail. I don't see any release numbers tied to the code, how can I know which Indy version will include this change? Share this post Link to post
Remy Lebeau 1401 Posted January 18, 2022 (edited) 20 hours ago, Der schöne Günther said: So looking at #395 Adding hcPATCH to THTTPCommandType · IndySockets/Indy@4813ee0 (github.com) that means my code for determining isPutOrPatch will now fail. Only because you were explicitly looking for CommandType=hcUnknown, which was not necessary to begin with. You could have simply done this instead: isPutOrPatch := (ARequestInfo.CommandType = THTTPCommandType.hcPUT) or TextIsSame(ARequestInfo.Command, 'PATCH') ; And that would have still worked fine with the CommandType change. Quote I don't see any release numbers tied to the code, how can I know which Indy version will include this change? Indy's release numbers were broken when Indy migrated from SVN to GitHub (issues #292 and #328), and that problem has not been addressed yet, but I do intend to ... some day, when I have time for it. However, the code is now live in Indy's master branch, and Lazarus' OPM has been updated to use this version (they have labeled it as version 10.6.2.4072). A future version of Delphi will pick up the change whenever Embarcadero decides to update their copy of Indy (usually in major IDE version releases). Edited January 18, 2022 by Remy Lebeau 1 Share this post Link to post
Fr0sT.Brutal 900 Posted January 18, 2022 5 hours ago, Remy Lebeau said: Only because you were explicitly looking for CommandType=hcUnknown, which was not necessary to begin with Well, that construction was logical (if command is not recognized, check its text verb) and faster (only do string compare for unknown ones) Share this post Link to post
Remy Lebeau 1401 Posted January 18, 2022 9 hours ago, Fr0sT.Brutal said: Well, that construction was logical (if command is not recognized, check its text verb) and faster (only do string compare for unknown ones) Yeah, well, now the check will be even faster, since you don't need the string comparison anymore. isPutOrPatch := (ARequestInfo.CommandType in [THTTPCommandType.hcPUT, THTTPCommandType.hcPATCH]); Share this post Link to post