Reconfigure URLs

When working here, we have a box serving XML feeds for business partners. Requests for our channels are configured by specifying the parameters and values ​​of the query string. Some of these parameters are necessary, but many of them are not.

For example, we require that all requests specify a GUID to identify the partner, and the request can either be for the "get the latest" or "search" action:

To search: http: //services.null.ext/? Id = [GUID] & q = [Search Keywords]
Recent data in the category: http: //services.null.ext/? Id = [GUID] & category = [ID]

Structuring a RESTful URL scheme for these parameters is easy:

Search: http: //services.null.ext/ [GUID] / search / [Keywords]
Last: http: //services.null.ext/ [GUID] / latest / category / [ID]

But how should we handle a dozen additional parameters that we have? Many of them are mutually exclusive, and many of them are necessary in combinations. Very quickly, the number of possible paths becomes extremely complex.

What are the recommended methods for matching URLs with complex query strings for friendlier / REST / ful / paths?

(I'm interested in conventions, schemes, templates, etc. Not specific technologies for implementing URL rewriting on a web server or within.)

+7
rest query-string
source share
2 answers

You must leave optional query parameters in the query string. There is no β€œrule” in REST that states that a query string cannot be. Actually, the opposite is true. The query string should be used to change the representation of the view that you pass back to the client.

Stick to Display State Objects for your URL path components. The category looks fine, but what exactly do you feed via XML? Messages? Directory items? Parts?

I think a much better REST taxonomy would look like this (assuming the contents of your XML feed is an "article"):

If you do not think about the objects that you represent when creating the REST structure, you do not perform REST. You do something else.

Check out this article on best REST methods . He is old, but he can help.

+4
source share

Parameters with values? One option is a query string. Using this is not an integral part of immunity. Another option is to use a half-time, Tim Berners-Lee talks about them , and they can just fit the bill, letting the URL make sense, without massive long paths.

+1
source share

All Articles