2

What drawbacks can you think of if I design my REST API with query strings without parameter values? Like so:

http://host/path/to/page?edit
http://host/path/to/page?delete
http://host/path/to/page/+commentId?reply

Instead of e.g.:

http://host/api/edit?page=path/to/page
http://host/api/delete?page=path/to/page
http://host/api/reply?page=path/to/page&comment=commentId

( Edit: Any page-X?edit and page-X?delete links would trigger GET requests but wouldn't actually edit or delete the page. Instead, they show a page with a <form>, in which page-X can be edited, or a <form> with a Really delete page-X? confiramtion dialog. The actual edit/delete requests would be POST or DELETE requests. In the same manner as host/api/edit?page=path/to/page shows a page with an edit <form>. /Edit. )

Pleace note that ?action is not how query strings are usually formatted. Instead, they are usually formated like so: ?key=value;key2=v2;key3=v3

Moreover, sometimes I'd use URLs like this one:

http://host/path/to/page?delete;user=spammer

That is, I'd include a query string parameter with no value (delete) and one parameter with a value (user=spammer) (in order to delete all comments posted by the spammer)

My Web framework copes fine with query strings like ?reply. So I suppose that what I'm mostly wondering about, is can you think of any client side issues? Or any problems, should I decide to use another Web framework? (Do you know if the frameworks you use provides information on query strings without parameter values?)

(My understanding from reading http://labs.apache.org/webarch/uri/rfc/rfc3986.html is that the query string format I use is just fine, but what does that matter to all clients and server frameworks everywhere.)

(I currently use the Lift-Web framework. I've tested Play Framework too and it was possible to get hold of the value-less query strings parameters, so both Play and Lift-Web seems okay from my point of view.)


Here is a related question about query strings with no values. However, it deals with ASP.NET functions returning null in some cases: Access Query string parameters with no values in ASP.NET

Kind regards, Kaj-Magnus

1 Answer 1

5

Query parameters without value are no problem, but putting actions into the URI, in particular destructive ones, is.

Are you seriously thinking about "restful" design, and having a GET be a destructive action?

Sign up to request clarification or add additional context in comments.

2 Comments

The ?edit query parameter would result in a page appearing, with a <form> with fields so you can edit the page. The actual edit request, when you click submit, would be a POST. The ?delete query parameter might show a page with a dialog "Delete page X?" in a <form> and the actual delete request would be a POST or a DELETE. So the ?action wouldn't actually do anything, only show pages on which you can submit forms. (Is this a reasonable design you think?) -- I'd better update my original question to clarify that ?delete doesn't delete.
Your motivation is ... a bit terse :-) "[they] are no problem". Well, I'll trust you, I'll just wait a while in case some other answer appears too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.