5
votes

I am implementing a REST server API in Delphi XE3 (first time using Delphi in about a decade so am a bit rusty). Currently it is using Indy server for debug purposes, but eventually it will be an ISAPI dll.

Now I have implemented a number of TDSServerClass classes and want to access the request header within the class methods. So for example when the user requests mysite.com/datasnap/rest/foo/bar I want to be able to read the header within the foo class method called bar. Is this possible?

If not, is it possible to create a global filter of incoming requests before they get to the REST class method? I need to check the API key and user authentication on incoming requests and not sure the best way to implement. Thanks.

1
Are you using the built-in authentication/authorization object?jachguate
No. API key and user token are passed in the request header. I need to read them.Joel
ps. Authentication should not be done at the server level as only some class methods require user authentication (token), and others do not (all methods require a valid API key).Joel

1 Answers

2
votes

I don't know if anything changed in XE3, but in XE2 you can do the following:

uses
  Web.HTTPApp,
  Datasnap.DSHTTPWebBroker;

function TServerMethods1.EchoString(Value: string): string;
var
  Module: TWebModule;
begin
  Module := GetDataSnapWebModule;
  Result := Module.Request.RemoteIP + ': ' + Value;
end;