#1 2019-12-10 19:59:37

fabiovip2019
Member
Registered: 2019-03-14
Posts: 76

Custom header by interface

Is it possible to work with TSQLRestServerURIContext different per interface? I would like to pass different headers per interface. I was using the Ctxt.Call.OutHead method but once defined for one interface all other interfaces on the same server will have the same header.

Offline

#2 2019-12-10 20:18:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,264
Website

Re: Custom header by interface

I don't understand how you set the output header.
It is a per-call context, so shouldn't affect the other interfaces.

Did you use the ServiceContext thread var?
See https://synopse.info/files/html/api-1.1 … ICECONTEXT

Offline

#3 2019-12-11 12:28:18

fabiovip2019
Member
Registered: 2019-03-14
Posts: 76

Re: Custom header by interface

Hi Ab,
I used the server.OnAfterURI method because when I tried to use it by CurrentServiceContext even passing the value to the Request.Call.OutBody property had no effect.

Offline

#4 2019-12-11 13:53:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,264
Website

Re: Custom header by interface

Some working possibilities:

1. use a method-based service
2. or define a TServiceCustomAnswer record as function result
3. or properly write your OnAfterURI event to only change the header for your interface, checking Ctxt.ServiceMethod^.InterfaceDotMethodName (if Ctxt.ServiceMethod is not nil)

Offline

#5 2019-12-11 20:44:05

fabiovip2019
Member
Registered: 2019-03-14
Posts: 76

Re: Custom header by interface

Hi Ab,
Thanks for the tips, I did as follows put TServiceCustomAnswer as a result of my function and it worked as I wanted.

  
    fTotalRows:= aPagParam.totalrows;

     TDocVariant.NewFast(response);
     TDocVariantData(response).AddValue('Result',res);
       for i:= Low(Data) to High(Data) do
      TDocVariantData(response).A_['Data'].AddItem(Data[i]);

     Result.Content:= VariantSaveJSON(response);
     result.Header:=  Trim(
     'totalrows: '+IntToString(fTotalRows)); 

See I'm forming content with DocVariant. My question is if this is the most correct way to format a DocVariant with TVariantDynArray? In this case the variable Data is TVariantDynArray and response is docvariant.

Offline

#6 2019-12-11 21:13:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,264
Website

Re: Custom header by interface

Use directly a

var
  response: TDocVariantData;

variable.

I guess you should add a Content header with proper JSON mime type too.

Offline

#7 2019-12-12 12:20:14

fabiovip2019
Member
Registered: 2019-03-14
Posts: 76

Re: Custom header by interface

Ok I modified, this is for array mounting is correct? Is there a way to pass a TVariantDynArray directly?


When you say mime type are you referring to application / json? Is this not standard in every mormot answer?

Last edited by fabiovip2019 (2019-12-12 12:25:31)

Offline

Board footer

Powered by FluxBB