Use XDataClient for non-XData rest servers

Hi,

I would like to use XDataClient for non-Xdata third party servers. As leveraging the xdata json parsing functionality with only an interface is pretty clean.

I have a few issues:

All Req.Uri get a trailing "/" added to the url. For example: "login.server.com/auth/" in stead of "login.server.com/auth". Some servers do not accept the trailing "/" and return a 404 error.

When using the x-www-form-urlencoded parameters (and maybe also the fromquery parameters, I haven't tested that one yet), all string values in the content body are quoted.
For example:
password=''xxxxxx''&username=''yyyyy''
This results in an error because other servers expect:
password=xxxxxx&username=yyyyy

It is possible to overwrite the THttpRequest, to make it work:

XDataClient.HttpClient.OnSendingRequest :=
procedure(Req: THttpRequest)
begin
  Req.Uri :=  'https://login.server.com/auth';
  Req.SetContent(TEncoding.UTF8.GetBytes('password=xxx&username=xxx'));
end;

Isn't there an easier way? For example two settings:

  • turn off trailing "/"
  • turn off quoted strings

Thank you!

The interface is based on:
https://support.tmssoftware.com/t/xdata-read-x-www-form-urlencoded-parameters/22715/4

For now the XData client will always add a trailing /. In this case you should indeed use the OnSendingRequest event and simply remove the trailing slash from the Req.Uri property.

For that you can replace the default URL string converter, this way:


uses
  {...}, XData.Model.Classes, XData.Aurelius.Model, XData.Types.Converters;

procedure ReplaceXDataStringConverter(ModelName: string = '');
var
  Model: TXDataModel;
  StringType: TXDataScalarType;
begin
  if ModelName = '' then
    Model := TXDataAureliusModel.Default
  else
    Model := TXDataAureliusModel.Get(ModelName);
  StringType := Model.DefaultSchema.FindScalarType('String');
  StringType.UrlConverter.Free;
  StringType.UrlConverter := TXDataUnquotedStringConverter.Create;
end;