Recent

Author Topic: rest api request object should accept json string  (Read 1416 times)

Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #15 on: September 22, 2022, 04:32:13 am »
please share the sample code .

KodeZwerg

  • Sr. Member
  • ****
  • Posts: 308
  • Fifty shades of code.
    • Delphi & FreePascal
Re: rest api request object should accept json string
« Reply #16 on: September 22, 2022, 05:29:22 am »
Have you even tried one of the samples/full projects??? You just repeat saying "give code please"
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

bytebites

  • Hero Member
  • *****
  • Posts: 505
Re: rest api request object should accept json string
« Reply #17 on: September 22, 2022, 08:08:56 am »
Post json-content like {"title":"Aida"}
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   {$ifdef UNIX}
  5.   cthreads, cmem,
  6.   {$endif}      
  7.   fphttpapp, httpdefs, httproute, fpjson, jsonparser;
  8.  
  9. procedure route1(aReq: TRequest; aResp: TResponse);
  10. var
  11.   s:string;
  12.   D,E : TJSONData;
  13. begin
  14.    writeln(areq.Content);
  15.    D:=GetJSON(areq.Content);
  16.    E:=d.FindPath('title');
  17.    s:=E.AsString;
  18. //   aResp.SetStatus(200);
  19.    aResp.Content:='<html><body><h1>Route 1 respone:'+s+'</h1></body></html>';
  20. end;
  21.  
  22. procedure route2(aReq: TRequest; aResp: TResponse);
  23. begin
  24.   aResp.Content:='<html><body><h1>Route 2</h1></body></html>';
  25. end;
  26.  
  27. begin
  28.   HTTPRouter.RegisterRoute('/', @route1);
  29.   HTTPRouter.RegisterRoute('/2', @route2);
  30.   Application.Port := 1999;
  31.   Application.Threaded := true;
  32.   Application.Initialize;
  33.   Application.Run;
  34. end.              
  35.  

Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #18 on: September 22, 2022, 09:14:29 am »
Please share me the sample code .

I will be most happy.

Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #19 on: September 22, 2022, 09:32:50 am »
Thanks . It is working .

Please help me how to handle CORS and SSL in pascal.

Regards,
Prakash

Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #20 on: September 22, 2022, 02:53:33 pm »
Have you even tried one of the samples/full projects??? You just repeat saying "give code please"

I am fresher in pascal because of that I am asking you the code.

I have done lot search on this. I am not getting any path for going ahead.

Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #21 on: September 22, 2022, 07:36:47 pm »
Thanks to everyone .

I have used following code . It is working for SSL .
  Application.Port := 7005;
  Application.CertificateData.PrivateKey.FileName:='xyz.key';
  Application.CertificateData.Certificate.FileName:='xyz.crt';
  Application.UseSSL:= true ;


Prakash

  • New Member
  • *
  • Posts: 16
Re: rest api request object should accept json string
« Reply #22 on: September 23, 2022, 07:09:20 am »
Does anyone is having full documents.

We would like to implement form,file upload request in pascal

 

TinyPortal © 2005-2018