0

i'm developing a rest API with TMS Sparkle and i would like to know the elegant way to read the customer {ID} from this request :

http://localhost/v1/customers/{ID}

I could just do reverse read in the final characters until i find a "/" character, but doesn't seen's the elegant way to me, there's another way to do it ?

This {ID} value is a part of the RequestedPath, but im wondering if there's a property which hold this value ?

I already read the documentation of the Examining the Request doc tutorial, but there's no mention of how read complementary values from the request.

Rebelss
  • 364
  • 1
  • 5
  • 15
  • 1
    Check the Sparkle.Utils unit. If I remember correctly, there are some utils to help you with this – John Kouraklis Mar 17 '20 at 09:01
  • Thank you for your response John, but i'm using trial, how can i check the Classes/methods of a unit without the source code ? – Rebelss Mar 17 '20 at 16:49

1 Answers1

1

When you inspect the Request you can access the different parts of it via the URI.Segments property like this:

procedure TMySparkleModule.ProcessRequest(const C: THttpServerContext);
var
  r: THttpServerRequest;
  str: string;
begin
  r:=C.Request;
  for str in r.Uri.Segments do
    ...
end;
John Kouraklis
  • 686
  • 4
  • 12
  • Thank you John, that is exactly what a was looking for. The Segments property is a string array containing all the segments of the url, for example : /v1/customer/70 would be Segments[0] = v1, Segments[1] = customer, Segments[2] = 70 – Rebelss Mar 26 '20 at 18:16