0
votes

I am creating a web service with play framework and scala. The service get a url and a language, and use this information, but i can't put a url into the service.

I have this in routes GET /trans/$url<(http%3A%2F%2Fa)>/:lang controllers.Application.getTranslation(url:String, lang:String)

and in Application: def getTranslation(iri: String,lang:String) = Action { implicit request => etc.

and i want to receive something like '/trans/htp://a/es' (its http instead of htp but i can't write it here)

is it posible? Because i've tried everything and i'm not able. is ther ane way to pass a url as parameter?

1

1 Answers

1
votes

You have to url escape and unescape on both sides. It is called URL Encoding or Percent Encoding (because escaped character are rewritten using a combination that start with %) https://en.wikipedia.org/wiki/Percent-encoding

Here is a question that give you information if your client side is in js: Encode URL in JavaScript?

And here is nice scala library that can be used to encode and decode URL persent encoding. https://github.com/theon/scala-uri

I have started scala myself (most of my prod work on playframework is still in Java), so I do not know if there is a better scala uri library out there.

EDIT : You got me curious so I searched a bit: http://www.motobit.com/util/url-encoder.asp you should be carefull about the encoding on both sides.