API REST - Opinión necesaria sobre arquitectura

I'm designing a REST API. The part I'm working on now involves simply reading objects in the form of JSON data off of the server and modifying them.

The resource that I am thinking of using for this looks like: /data/{table name}/{row key}

I would like to allow GET y PUT operations on this resource.

The question that I am wrestling with is that I would like to return other data along with the JSON object such as customer messages, the amount of time it took for the round trip to the data base, etc... I would also like to allow for sending query arguments with the payload in cases where the URL would be too long if they were included there.

So the resources would work like this:

GET /data/{table name}/{row key}

Server returns:

   data:{...JSON OBJECT GOES HERE ....},
   message:"customer messages go here",
   otherInfo:"Yada yada yada;


PUT GET /data/{table name}/{row key}

Client sends as payload:

   data:{...JSON object goes here...},
   queryArguments:{...extra long query arguments go here...}

I'm afraid this might violate the rules for proper RESTful GET y PUT resources because what you are sending to the server is not exactly what you are getting back out since other information is being included in the payloads. I'd rather not have every operation be a POST como remedio.

Am I being too much of a stickler with this? Is there some other way I should be structuring this?



I should note that in the resource: /data/{table name}/{row key}, I used 'table name' and 'row key' for simplicity. This is for use with a noSQL database. This resource is intended to work similar to Amazon S3. "uuid" would actually be a better description than 'row key'.

preguntado el 08 de enero de 11 a las 19:01

That layout looks a lot like Shoji: aminus.org/rbre/shoji/shoji-draft-02.txt -

3 Respuestas

I see nothing wrong with your approach.
But if I was implementing this scenario, I would have asked myself the following questions:

  1. Who is my resource?
  2. Is customer message part of the resource?
  3. Is "response time" is part of the resource?

Let's take as an example "response time". If it's part of your resource, your approach is perfect and nothing else should be done.
However, if it's not part of the resource, return it as a HTTP header. Fair enough.

Respondido el 11 de enero de 11 a las 23:01

As for me it just depends on how additional info is going to be used. For my customers responseTime is not a question (or at least I think so :), they just need that response. For me as developer it can help debugging. So when customer gives me slow request I can test it easy, and that extra information could help. Here I mean that it is possible to create simple url as you specified /data/{table name}/{row key} and send just response according to that request, and you can make one more url /data/{table name}/{row key}/debug or whatever else to get the same data with additional info like "reponseTime". Just an idea ;)

ACTUALIZACIÓN: Ah yes, forgot: do not use table-name as part of your url, at least modify its name. I don't like to tell anybody how my tables are called, if somebody is going to hack my DB injecting extra code I would like her to spend more time looking for any information, instead of giving her info on a plate :)

Respondido el 08 de enero de 11 a las 23:01

I don't see anything wrong with this, looks pretty standard to me. I'm not sure what you are planning to pass in queryArguments, is this where you would specify a callback to execute for JSON-P clients? Only thing I'd recommend you keep in mind is that REST deals with resources, and that does not necessarily map 1-to-1 with tables. Instead of using a row key you might want to have some type of GUID or UUID that you can map to that resource.

Respondido el 08 de enero de 11 a las 23:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.