views:

32

answers:

2

Given a path to a REST style URL:

http://site.com/rest/customer/foo/robot/bar/1

When you GET it, it returns a PDF to the foo-customer containing page 1 of the bar-URL.

While foo is the name of the customer bar is an URL. The URL usually contains slashes and might look something like this:

http://anothersite.com/interestingarticle.html

As REST URL's separate arguments by slashes I can't just put it into the REST URL above. Which encoding should I use? I can't use Base 64 as it utilizes the slash as well.

As a technical note I will encode the URL in a .NET-application and decode it in PHP.

+1  A: 

What is your use case exactly? Why does bar need to be a URL? The server can construct the URIs any way it wants to.

If you for some reason MUST use the URL, do this:

http://site.com/rest/customer/foo/robot?bar=http://anothersite.com/interestingarticle.html&page=1

(with urlencoded query string of course).

Jan Algermissen
Thank you for your answer! My use case isn't creating PDF's. But I *must* send an URL through REST so the example is valid. Your way doesn't allow for additional arguments to further drill down into the URL. And it doesn't conform to the REST style of creating URL's.
Binary255
Why are you saying that my way does not allow additional args? BTW: There is no such thing as a "REST style for creating URLs". The URL I show is just a perfectly valid URL (except for the not shown url encoding of the QS of course).
Jan Algermissen
I thought the URL's should be created so that more paramters can be appended to drill down further into the selection. Maybe that is not the case. Using that style I won't be able to add more parameters after the URL, which is what I want to do. Using some kind of encoding.
Binary255
You can append any number of query parameters to my example URI. E.g. you can append b=2/bar/... and have the property of not 'stopping' the hierarchy. IOW, you can use path segments after the parameters to indicate further drill down.
Jan Algermissen
Yes I guess your method is a possibility. However I'm pretty set on using parameters separated by slashes. It's how I've seen all REST example.
Binary255
+1  A: 

By double URL-encoding the URL it will never contain any slashes and may therefore use parameters separated by slashes.

The URL is encoded and sent from .NET using C#:

String url = "http://urltoencode.com/a/page";
System.Text.Encoding westernEuropeanISOencoding = System.Text.Encoding.GetEncoding("iso-8859-1");
String doubleEncodedUrl = System.Web.HttpUtility.UrlEncode(url, westernEuropeanISOencoding);
doubleEncodedUrl = System.Web.HttpUtility.UrlEncode(doubleEncodedUrl, westernEuropeanISOencoding);

The receiving PHP-script double decodes the URL:

url = decode(decode($receivedDoubleEncodedUrl));
Binary255