Missing something with IWebRequest:GetPathParameter() - We

Posted by slacroixak on 24-Sep-2019 06:31

OE 11.7.5  What am I missing with the GetPathParameter method?

The doc says about GetPathParameter() :  Get a parameter from the URI path if URI template matching was used.

I test it with a sample WebService with a WebHandler that does the following in the HandleGet() method:

[...]   
DEFINE VARIABLE oBody        AS OpenEdge.Core.String  NO-UNDO.
DEFINE VARIABLE cwhere       AS CHARACTER             NO-UNDO.
DEFINE VARIABLE curi         AS CHARACTER             NO-UNDO.
DEFINE VARIABLE curiTemplate AS CHARACTER             NO-UNDO.            

ASSIGN
    oResponse            = NEW OpenEdge.Web.WebResponse()
    oResponse:StatusCode = INTEGER(StatusCodeEnum:OK)
    cwhere               = poRequest:GetPathParameter("pcwhere")
    curi                 = poRequest:URI:toString().
    
oBody = NEW OpenEdge.Core.String(SUBSTITUTE
    ( 'Hello World~n  pcwhere=&1~n  uri=&2  ~n  UriTemplate=&3'
    , QUOTER(cwhere)
    , QUOTER(curi)
    , QUOTER(curiTemplate))).

ASSIGN
    oResponse:Entity        = oBody
    oResponse:ContentType   = 'text/plain' /* HTTP messages require a content type */
    oResponse:ContentLength = oBody:Size.  /* ContentLength is good too */
[...]

This request with Postman : localhost:8810/AKQWeb/web/TestGetParam?pcwhere=bladibla

Results in the following response :

Hello World
  pcwhere=""
  uri="localhost:8810/.../TestGetParam  
  UriTemplate="/TestGetParam"

Indeed, I was expecting 'bladibla' for pcwhere.  Because of that, I have to make my own GetPathParameter() method

What am I missing ?

Posted by asengupt on 24-Sep-2019 13:10

Sorry - should be GetContextValue("QUERY_STRING"), but Peter's method is more appropriate.

Posted by Peter Judge on 24-Sep-2019 13:06

As Geir Otto says, path parameters are resolved URI path tokens.
 
You need to set them up in the handler configuration (similar to below) before you can use them.
handlerN=MyWebHandler: /v1/Customers/{OrganisationId}
 
If you want to get a query string value, use
pRequest:URI:GetQueryValue('name')
 
 
 
 
 
 

All Replies

Posted by goo on 24-Sep-2019 06:58

I am not sure if I follow you. I am using it now and if I have this URL:
 
 
and sends this:
 
I am able to get opRequest:GetPathParmeter(‘OrganizationId’) with a value of 22.
 
You have to look at query_string to get what you want.
 
opRequest:GetPathParmeter(‘query_string’) will give:
 
pcwhere=bladibla
 
 
//Geir Otto
 

Posted by asengupt on 24-Sep-2019 13:02

?pcwhere=bladibla seems to be a query parameter. Perhaps try using GetContextValue("pcwhere"). This should return a string containing the query. If there are multiple queries, joined by the '&' symbol (for example custid=2&orderid=2) you get all the queries in a single string.

See the How to get a query parameter value section on this page: https://docs.progress.com/bundle/service-developer-guide/page/Use-a-Web-Handler.html

Posted by Peter Judge on 24-Sep-2019 13:06

As Geir Otto says, path parameters are resolved URI path tokens.
 
You need to set them up in the handler configuration (similar to below) before you can use them.
handlerN=MyWebHandler: /v1/Customers/{OrganisationId}
 
If you want to get a query string value, use
pRequest:URI:GetQueryValue('name')
 
 
 
 
 
 

Posted by asengupt on 24-Sep-2019 13:10

Sorry - should be GetContextValue("QUERY_STRING"), but Peter's method is more appropriate.

Posted by slacroixak on 24-Sep-2019 16:06

Thank you guys.  Indeed, poRequest:URI:GetQueryValue() is the appropriate method to do the job.  I was expecting GetPathParameter() to support everything present in the URI but I can now the a pathParam is a value as you say.

Peter, perhaps you can tell why the PDS cannot provide intellisense for the URI member ?  I mean, having the carret after poRequest:URI:   Ctrl-Space gives ABL low level attributes and methods instead of the Members of the OpenEdge.Net.URI class.

This thread is closed