Search code examples
resthttp-method

Is it a preferred way to reuse a url with different http methods?


For example, when making a payment with credit-card we POST to url /paymybill-cc. And we want to avoid reposting when the user refresh the page. In this case, is it a preferred way to redirect to the same url with GET method?


Solution

  • Usually the POST happens to a url specifying what you want to create, like in your case, but the GET should happen to a url like /paymybill-cc/:id to get a specific one.

    If I were allowed to GET /paymybill-cc I would expect it to return all payments, maybe with a default limit, but a lot of them.

    If the user reloads the page that contains POST data then he will be prompted about resubmitting his data to the server. See How do I reload a page without a POSTDATA warning in Javascript? for a bit more details on that.