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 ?
Sorry - should be GetContextValue("QUERY_STRING"), but Peter's method is more appropriate.
?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
Sorry - should be GetContextValue("QUERY_STRING"), but Peter's method is more appropriate.
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.