You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Jonathan Kanarek <Jo...@kaltura.com> on 2015/04/01 07:46:25 UTC

RE: Global arguments

Thanks a lot, I'll try the first (simple) approach.

T.

-----Original Message-----
From: Jens Geyer [mailto:jensgeyer@hotmail.com] 
Sent: Tuesday, March 31, 2015 9:23 PM
To: user@thrift.apache.org
Subject: Re: Global arguments


Oh, I forgot: There is some work on the THeader support, but this is (AFAIK) not production-ready yet, and only supported by C++ right now.

JensG



-----Ursprüngliche Nachricht-----
From: Jens Geyer
Sent: Tuesday, March 31, 2015 8:18 PM
To: user@thrift.apache.org
Subject: Re: Global arguments

Hi Jonathan,

> I would like to implement Kaltura server API using thrift.

Great!

> [...] add global list of arguments to all requests [...] such as 
> client library version, client tag, account id, session id and few 
> more, these arguments could be added to any request but none of them 
> is required.

Since the Thrift IDL is by design lacking the concept of inheritance, we came up with another solution for our projects.

    // data common to all requests
    struct ApiRequest {
          1 : optional string SessionID
          2 : optional string MsgID
          3 : optional string ApiKey
    }

The first approach could be straightforward like so:

    service Foobarizer {
        ProductDetails GetProductDetails( 1 : ApiRequest request, 2: string
productID)
    }

For some other reason, we decided to do it slightly different, like so:

    // data for one particular request
    struct GetProductDetails {
          1 : required ApiRequest base_            // data common to all
requests
          2 : required string ProductID
          3 : optional DetailsOfInterest DetailsOfInterest  // that's another structure
    }


    service Foobarizer {
        ProductDetails GetProductDetails( 1 : GetProductDetails request) throws ( 1: RemotableException rex)
    }

And then we did the same with our responses, which all contain a similar structure field:


    // response base class
    struct ApiResponse {
          1 : optional string SessionID
          2 : optional string CorrelationID  // the MsgID taken from the request
          3 : optional list<ErrorEntry> WarningsAndErrors
    }

    struct ProductDetails {
          1 : required ApiResponse base_            // data common to all
requests
        // ... other data as needed ...
    }


So far we made good experiences with that approach, especially as it is easily maintanable and extendable, and the base_ field has a common structure that can be handled in a centralized manner.

Have fun,
JensG


-----Ursprüngliche Nachricht-----
From: Jonathan Kanarek
Sent: Tuesday, March 31, 2015 7:58 PM
To: user@thrift.apache.org
Subject: Global arguments

Hi,
I would like to implement Kaltura server API using thrift.
I couldn't find if and how is it possible to add global list of arguments to all requests.
I have list of optional arguments, such as client library version, client tag, account id, session id and few more, these arguments could be added to any request but none of them is required.
How would you define such arguments in the interface?

Thanks,
Tan-Tan.