reen
reen

Reputation: 2502

How to get Request Parameter from Context in Play Framework

Hi have the following routes file:

POST        /user/:id           controllers.Application.updateUser(id: Long)

Is there an easy way to get the value from the Http.Context? The context.request().queryString() is always empty.

Upvotes: 0

Views: 1915

Answers (2)

Roshan Dissanayake
Roshan Dissanayake

Reputation: 1

context.request()._underlyingRequest().getQueryString(<ID>)

Upvotes: 0

James Roper
James Roper

Reputation: 12850

context.request().queryString() only returns query string parameters, whereas you're putting the id in the path. If you want to get it, you have to extract it out of path yourself, eg:

long id = Long.parseLong(context.request().uri().substring(
    context.request().uri().lastIndexOf('/') + 1));

Upvotes: 3

Related Questions