#1 Re: mORMot 1 » Custom routing on method based service » 2025-09-24 13:23:45

For my scenario I think another root uri for method based service is the best choice.

What I would like to obtain, if possible, is to have some routes like (for example):

http://ip:port/api/checkout
http://ip:port/api/print
http://ip:port/api/coupons/claim
http://ip:port/api/coupons/release

and all methods (Checkout, Print, ClaimCoupon, ReleaseCoupon) should belongs to the same TSSPOSRESTProcessor class:

  TSSPOSRESTProcessor = class(TSQLRestServerFullMemory)
  private
    ...
  published
    function Checkout(AContext: TSQLRestServerURIContext): RawJSON;
    function Print(AContext: TSQLRestServerURIContext): RawJSON;
    function ClaimCoupon(AContext: TSQLRestServerURIContext): RawJSON;
    function ReleaseCoupon(AContext: TSQLRestServerURIContext): RawJSON;
  end;

I know that it's not the best choice, but I found most of the code already written, and I can't actually rewrite it in a better way.

#2 Re: mORMot 1 » Custom routing on method based service » 2025-09-24 13:05:35

Can you provide a quick example ?

I'm unfamiliar with URL rewriting, and I didn't find an example that show how to do id.

Many thanks

#3 Re: mORMot 1 » Custom routing on method based service » 2025-09-24 11:07:04

ab wrote:

Sorry for the delay on response.

I read the article, but I can't find a Route method on TSQLHttpServer class.

BTW, I'm still using mORMot 1, maybe I should use another approach ?

Thanks again

#4 mORMot 1 » Custom routing on method based service » 2025-09-22 14:57:52

g_garzotto
Replies: 8

Hello,

I have a method based service that expose a series of method.
The constructor of service create a model that define an api route:

constructor TSSPOSRestServer.Create(APort: Integer);
begin
  FPort := IntToStr(APort);

  FModel := TSQLModel.Create([], 'api');
  FService := TSSPOSRESTProcessor.Create(FModel);
  FServer := TSQLHttpServer.Create(FPort, [FService], '+', useHttpApiRegisteringURI);
  FServer.AccessControlAllowOrigin := '*';
end;

so the methods are available at URL:

http://ip:port/api/mymethod

There is a simple way to add another model to the current server, in order to have some methods that use another routing ? For example:

http://ip:port/orders/myothermethod

Or, there is a way to define custom routing for method based services ? I read about TSQLRestServerURIContext class, but I can't figure out how to use it.

Thanks in advice

#5 Re: mORMot 2 » Different behaviour of HmacSha1 between Delphi and Postman CryptoJS » 2025-02-07 07:46:16

Didn't notice the URI, you're right.

The following code works fine:

procedure TForm1.btnGeneraCodiceClick(Sender: TObject);
const
  SECRET_KEY: RawByteString = 'myPrivateKey12345!!';
var
  sData,
  sSignature64: RawByteString;

  SHAOutput: TSHA1Digest;
begin
  sData := 'POS-1|2025-01-25|43';
  HmacSha1(SECRET_KEY, sData, SHAOutput);
  sSignature64 := BinToBase64(@SHAOutput, 20);
end;

Thanks

#6 mORMot 2 » Different behaviour of HmacSha1 between Delphi and Postman CryptoJS » 2025-02-06 11:36:55

g_garzotto
Replies: 2

Hello,

I'm using Delphi 7 and mORMot2.

This code:

procedure TForm1.btnGeneraCodiceClick(Sender: TObject);
const
  SECRET_KEY: RawByteString = 'myPrivateKey12345!!';
var
  sData,
  sSignature64: RawByteString;

  SHAOutput: TSHA1Digest;
begin
  sData := 'POS-1|2025-01-25|43';
  HmacSha1(SECRET_KEY, sData, SHAOutput);
  sSignature64 := BinToBase64URI(@SHAOutput, 20);
end;

returns in variable sSignature64 the value

AwxPbTUf5OGaFaxmmV6HwgpA0wU

which have a lenght of 27 chars.

The following code executed in Postman:

var CryptoJS = require('crypto-js');

var secretKey = "myPrivateKey12345!!";
var dataString = "POS-1|2025-01-25|43";

var signatureBytes = CryptoJS.HmacSHA1(dataString, secretKey);
var signatureBase64 = CryptoJS.enc.Base64.stringify(signatureBytes);
console.log("signatureBase64: ", signatureBase64);

returns in variable signatureBase64 the value

AwxPbTUf5OGaFaxmmV6HwgpA0wU=

which have a lenght of 28 chars.

I can't figure out if I wrong something in my code, or if there are some issues in the code.

I found the same behaviour also in mORMot 1.

Can you point me in some directions to solve my problem ?

Thanks in advice, regards

Giuseppe Garzotto

#7 Re: mORMot 1 » Read entire body of a POST call from server » 2023-09-07 15:37:47

Yes, one minute after submit I found what I need in another post.

Ctxt.Call.InBody solve all my needs.

Thanks

#8 mORMot 1 » Read entire body of a POST call from server » 2023-09-07 15:20:18

g_garzotto
Replies: 2

I have defined a method based service.

I need to perform a POST call from a client (initially Postman, in production will be an Angular application).

I would  like to read entire body of the call, that will contain a complex JSON that I need to parse.

How can do it ?

Thanks in advice

Board footer

Powered by FluxBB