Jump to content
chkaufmann

THTTPCommandType - PATCH

Recommended Posts

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

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 by Der schöne Günther

Share this post


Link to post
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 by Remy Lebeau

Share this post


Link to post
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 by Remy Lebeau
  • Thanks 1

Share this post


Link to post
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×