B4J Question Getting the request params from the url

coldflame

Member
Hi @aeric , I was going through your WebApi templates and I noticed that you implemented the /api/v1/products/{productId} pattern. Can you please work me through it please??
I am building an api without using the WebApi templates(I have gone a bit far in the project).
Thanks
 

aeric

Expert
Licensed User
Longtime User
Getting the request params from the url

B4X:
Sub Class_Globals
    Private Request As ServletRequest
End Sub

Request.RequestURI      ' Returns the request URL without the host and any parameters
Request.FullRequestURI  ' Returns the full request URL including the scheme, host and parameters
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
May be it is just a bad definition but the parameters in an URL comes after the question mark ? and they are pair of key and values. the best way to get them is:

B4X:
   dim parameters as map =  req.ParameterMap

if what you want is the embbeded id inside the URL then aeric answer is correct.
 
Upvote 1

aeric

Expert
Licensed User
Longtime User
You are right. I just realized I have misunderstood the question.

If the URL is like http://localhost:8080/web/api/v1/products/?id=3, then you can get the value of id by:

B4X:
Dim id As String = Request.GetParameter("id")
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…