Home > Software engineering >  Force last '/' inside TRESTClient.BaseURL Method
Force last '/' inside TRESTClient.BaseURL Method

Time:09-30

I'm trying to reach an api with this request url :

https://myapi/api/v4/contract/id/recipients/

In my code it looks like that :

var
  RESTClient : TRESTClient;
  ...

begin 
  RESTClient := TRESTClient.Create('');
  try
    RESTClient.BaseURL := 'https://myapi/api/v4/contract/id/recipients/';
    ShowMessage(RestClient.BaseURL);
    ...
  finally
    RESTClient.Free;
  end;
end;

But instead of the URL I put inside my RESTClient.BaseURLit shows me:

https://myapi/api/v4/contract/id/recipients

Is there a method that can force the last /? I tried the IncludeTrailingPathDelimiter method but that added a \instead. I also found a IncludeTrailingSlashmethod but my compiler did not recognise it.

CodePudding user response:

Assuming that you are using a TRESTRequest together with the TRESTClient, you should split the URL into the real BaseURL https://myapi/api/v4 for the client and the Resource part contract/id/recipients/ for the request. That way the combined URL for this request will contain the ending slash.

See: TRESTRequest.Resource

  • Related