title: How to design RESTful search/filtering?
body: <p>I'm currently designing and implementing a RESTful API in PHP. However, I have been unsuccessful implementing my initial design.</p>
  
  <pre><code>GET /users # list of users
  GET /user/1 # get user with id 1
  POST /user # create new user
  PUT /user/1 # modify user with id 1
  DELETE /user/1 # delete user with id 1
  </code></pre>
  
  <p>So far pretty standard, right?</p>
  
  <p>My problem is with the first one <code>GET /users</code>. I was considering sending parameters in the request body to filter the list. This is because I want to be able to specify complex filters without getting a super long url, like:</p>
  
  <pre><code>GET /users?parameter1=value1&amp;parameter2=value2&amp;parameter3=value3&amp;parameter4=value4
  </code></pre>
  
  <p>Instead I wanted to have something like:</p>
  
  <pre><code>GET /users
  # Request body:
  {
      "parameter1": "value1",
      "parameter2": "value2",
      "parameter3": "value3",
      "parameter4": "value4"
  }
  </code></pre>
  
  <p>which is much more readable and gives you great possibilities to set complex filters.</p>
  
  <p>Anyway, <code>file_get_contents('php://input')</code> didn't return the request body for <code>GET</code> requests. I also tried <code>http_get_request_body()</code>, but the shared hosting that I'm using doesn't have <code>pecl_http</code>. Not sure it would have helped anyway.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/978061/http-get-with-request-body">this question</a> and realized that GET probably isn't supposed to have a request body. It was a bit inconclusive, but they advised against it. </p>
  
  <p><strong>So now I'm not sure what to do. How do you design a RESTful search/filtering function?</strong></p>
  
  <p>I suppose I could use <code>POST</code>, but that doesn't seem very RESTful.</p>