Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help on servicestack implementation

Tags:

servicestack

I an facing issue with my servicestack implementation, i have make followings requests url to call my service and implemented one perfmon class & perfmonservice class

    [RestService("/perfmon/application/{appliationId}")]
    [RestService("/perfmon/application/{appliationId}/{countername}")]
    [RestService("/perfmon/user/{userId}")]
    [RestService("/perfmon/user/{userId}/{countername}")] 

Now when i will call any of the URL it would call following function

 public override object OnGet(Perfmon request)
        {                
                return base.OnGet(request);
        }

so how can i decide here that which URL made this call , weather servicestack provide any specific way to do this or i need to write manual logic by checking properties?

Thanks in Advance

like image 408
Arun Rana Avatar asked Nov 04 '11 09:11

Arun Rana


1 Answers

Just inspect the request DTO to see which fields are populated, i.e.

if (request.applicationId != null && request.countername != null) #2
if (request.userId != null && request.countername != null) #4
if (request.applicationId != null) #1
if (request.userid != null) #3

Also note that the user can populate the request dto with the querystring as well, i.e. if they called you with:

/perfmon/application/1/countername?userId=2

Then all fields will be populated. Lastly you can retrieve information about the Request with like the Absolute URI used to call the request with:

base.RequestContext.AbsoluteUri

Finally you can get the IHttpRequest object itself with:

var httpReq = base.Request; //or with base.RequestContext.Get<IHttpRequest>();
like image 154
mythz Avatar answered Oct 12 '22 03:10

mythz