4

I have an application running with AS2/PHP. The AS2 communicate with PHP scripts via $_POST array of data, this array contains data like sessionkey, userID, and some database filtering (sql limit, order by etc.)

An iOS version of the application is planned, and I am trying to figure out the best way to use the existing server side code and rewrite only the graphics.

The problem is that I need a lot of data, data which ideally should be sent via $_POST array into a GET http request (sorry if I am not clear, don't hesitate to ask me questions).

I've read this post Understanding REST: Verbs, error codes, and authentication which made me understand better how REST should be working, but I need more data sent to server.

For example, let's say I'd like to retrieve a collection of items, the request would be something like:

GET http://xxx/rest/item

But how do I tell the server that i'd like to retrieve only X elements from the collection, or even which sort order i'd like ?

Thanks previously for your answers

EDIT: @laurent, here an example of a script POST parameters received:

    // COMMON PARAMETERS (each script)
$idPROF     = Utils_Mv::getVariablePOST('idPROF');
$idVISITE   = Utils_Mv::getVariablePOST('idVISITE');
$typeConnexion  = Utils_Mv::getVariablePOST('typeConnexion');
$typeSupport    = Utils_Mv::getVariablePOST('typeSupport');
$cleSession     = Utils_Mv::getVariablePOST('cleSession');
$idCLIENT   = Utils_Mv::getVariablePOST('idCLIENT');
$idCONTEXTE = Utils_Mv::getVariablePOST('idCONTEXTE');

    // SCRIPT-SPECIFIC PARAMETERS
$idSUIVI        = (int) Utils_Mv::getVariablePOST('idSUIVI');
$nbPrescription = (int) Utils_Mv::getVariablePOST('nbPrescription');
$indiceDebut    = (int) Utils_Mv::getVariablePOST('indiceDebut');
$critereTri     = Utils_Mv::getVariablePOST('critereTri');
$isTriInverse   = Utils_Mv::boolval(Utils_Mv::getVariablePOST('isTriInverse'));
$chaineFiltres  = Utils_Mv::getVariablePOST('chaineFiltres');

You would pass the common parameters as get parameters on GET request ? (and POST for PUT/POST)

Community
  • 1
  • 1
kitensei
  • 2,510
  • 2
  • 42
  • 68

1 Answers1

6

To get more than one item, I would do something like this:

GET http://example.com/items/1_2_3_4

Where 1, 2, 3, 4 are the item IDs. To get just one item, you would do:

GET http://example.com/items/1

For the sort order, I would make this a query parameter. In general, a REST URL should point to a resource or several resources. Anything extra like sort order, resource format, etc. should be a query parameter:

GET http://example.com/items/1_2_3?order=by_name
laurent
  • 88,262
  • 77
  • 290
  • 428
  • and what about "credentials" data ? like session key, client ID or any other data that is necessary for the request but doesn't directly filter the result ? – kitensei May 31 '12 at 09:57
  • @Kitensei, the session key should also be a query parameter since it might be necessary for both GET and POST requests. Not sure about the client ID - can't you derive it from the session key? If not, it should probably be a query parameter too. – laurent May 31 '12 at 10:03
  • i've edited my question to show the parameters I use to send/receive, the application is already huge and wasn't developed by me, so the less modifications I make the best it is. – kitensei May 31 '12 at 10:08
  • Obviously I don't know your system, but presumably all the POST variables represent a resource, so they should stay as POST data. Everything else, critereTri, triInverse, etc., no matter how many there are (though you should try to use reasonable defaults to reduce them) should always be query parameters. – laurent May 31 '12 at 12:48