I want to implement REST server Is it possible with Delphi tokyo (10.2) (including session certification)?

Asked 2 years ago, Updated 2 years ago, 132 views

Hi, how are you?

With the current Delphi 10.2 (tokyo) version, server, cla, in JSON type with the source implemented by the existing developer

We are making simple Android programs such as linking between Eant and checking Nexus db values.

The problem is that if the pre-implemented source sends the server ip and method, the result value is

regardless of login (authentication session)

You will respond no matter what. So additionally, when logging in to a client from another server, the authentication key or token value is

I only know the theoretical aspects that should be included in the header when I create and receive requests and responses.

Question: Is it possible to implement these in Delphi 10.2 version?

can be implemented, sauce or a simple example, can I get?

Below are some of the current sources

procedure TfrmMain.ServerStart;
begin
  fServer := THttpApiServer.Create(false);
  fServer.AddUrl('temporary address', '80', false, '+', true); << temporary address is arbitrarily hidden.
  fServer.RegisterCompress(CompressDeflate);
  fServer.OnRequest := Process;
end;

function TfrmMain.Process(Ctxt: THttpServerRequest): cardinal;
var
  FN : RawUTF8;
begin
  FN := StringReplaceChars(UrlDecode(copy(Ctxt.URL,10,maxInt)),'/','\');

  if (UpperCase(Ctxt.Method) = 'POST') then
  begin
    if (FN = 'getServerIP') then
    begin
      Ctxt.OutContent := StringToUTF8(DM.getServerIP(UTF8DecodeToUnicodeString(Ctxt.InContent)).ToString);
      Ctxt.OutContentType := JSON_CONTENT_TYPE;
      result := 200;
    end
    else if (FN = 'doLogin')then
    begin
      Ctxt.OutContent := 
    StringToUTF8(DM.doLogin(UTF8DecodeToUnicodeString(Ctxt.InContent)).ToString);
      Ctxt.OutContentType := JSON_CONTENT_TYPE;
      result := 200;
    end
    else if (FN = 'Personal Information Inquiry')then
    begin
      Ctxt.OutContent := 
    StringToUTF8(DM.doLogin(UTF8DecodeToUnicodeString(Ctxt.InContent)).ToString);
      Ctxt.OutContentType := JSON_CONTENT_TYPE;
      result := 200;
    end


It's like this

Currently, http://temporary address/doLogin << user login stage is not required 

You can inquire personal information by requesting. DoLogin and maintain the session to load other methods

How should I implement it? 초 I hope you can write it easily because it's a beginner.

delphi rest api session

2022-09-22 08:11

1 Answers

I don't know Delphi, but I looked it up and found that You can also use JSON Web Token on Delphi.

Simply put, when you log in, the server returns a string to the client, and when you decrypt it, it's actually a string that contains the login's identification and all the necessary information, and the login will have it as a cookie or file, and then request a HTTP string somewhere when you need authentication. The server then decrypts the content when the header is present, and responds to the request processing that is appropriate to the person with the identification information contained therein only when the content is normal.

JWT is difficult to say, in short, session + information arrangement. You can use it if you decide to. Try it.


2022-09-22 08:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.