Mike
Mike

Reputation: 485

Get form parameters from a post request using spray/scala

I'm really new with all this Scala/Spray. With some testing I was able to get parameters from a Get request using the parameters function. However I'm trying to fetch some parameters sent from a POST request on the body of the request. It seems like parameters function is unable to fetch those values.

As an example, I'm trying to get this values "name=john&lastname=smith" from the post request body. What is the best option to get these values?

Thank you

Upvotes: 12

Views: 7286

Answers (3)

Robin Green
Robin Green

Reputation: 33063

As of recent Spray versions, you need to use the Unmarshaller for FormData.

Upvotes: 0

Edi
Edi

Reputation: 640

You could use [Form-Field-Filters] to extract parameters from POSTs

[Form-Field-Filters] https://github.com/spray/spray/wiki/Form-Field-Filters

Upvotes: 5

Don Roby
Don Roby

Reputation: 41137

Indeed, the parameters directive only handles things actually in the query-string and not parameters in the body of the request. To get things out of the body, you'll need to use the content directive and then unmarshal the content.

This spray-user thread may be helpful, as it includes some unmarshalling code doing precisely what you're looking for.

Upvotes: 4

Related Questions