I have converted a RODL based service to Code First so that I can use the new HTTP API. However, there is a lack of detail in the documentation and samples on how to do anything. For example, the documentation says I can use the ServiceRequiresLogin option to replicate the old way. But there is no mention of how, nor any reference in any of the library code. And what about the “old” RequiresSession property in the DataModule - that is still there - is that the real answer still?
Likewise there is a lack of information on the new HTTP API and the attributes and how to use them. I also note that there is an option to support HTTP response codes through exceptions, but how is this handled for the “old” function use? Do I have to define two functions, one for old, one new?
I’d much appreciate some worked examples of all of the options. It would also be good to have more complex examples of a service with a separate login service - all the samples seem to be very simple.
Thanks for moving it all forward though - looks good. I just need to know how to use it!
Thank you for the response. Yes, it does look like the .Net info is mixed in with the Delphi info quite a bit - that page doesn’t make it clear that it is different.
I would like to know how to handle responses differently according to how the API is called - an HTTP exception causes what to happen when called with the old clients?
I shall separate my questions, so will create a new question on out parameters.
you can create http api wrappers for your existing methods that will return required codes, like
function TMyService.httpapi_wrapper_for_method1(...): ...;
begin
try
result := method1(...);
except
on e: EMYException1 do raise EROHttpApiException.Create(my_httpapi_code1);
on e: EMYException2 do raise EROHttpApiException.Create(my_httpapi_code2);
on e: Exception do raise EROHttpApiException.Create(my_httpapi_code3);
end;
end;
another possibility is detect http api call in OnGetDispatchInfo event and raise correspondent error in old method
Sorry to resurrect this but I’m looking at the HttpApi stuff in Delphi myself now.
The above example doesn’t seem to work properly. The login call succeeds with a 200 result and the memo shows a session created but all the other calls fail with a 401, regardless of whether I’ve called login to create the session.
I’m not sure what you mean by test case - I’m just using the example httpapi_security.zip above. I’ve just downloaded it, run it, then copied the swagger json it produces into Postman so I can call the endpoints.
Login works and returns 200 and I see the new session in the memo control. All three remaining calls return 401.
If I breakpoint both Login and Logoff functions in the login service, again login works fine but logoff doesn’t even get to the service function.
Just tried implementing this in my own app but having problems with the Logoff.
Logon works fine and establishes a session but, if I then add this to an Access-Token head in my Logoff call, it doesn’t make it through to the function. Inspecting ClientID in the Logoff shows a different GUID each time it’s called.
Do I need to do something else to get the value of the Access-Token header to be used correctly?