Diseño RESTful URI: múltiples URI para recursos fáciles de usar

Suppose I have the following entities: project, company, director.

Se aplican las siguientes relaciones:

  • A project has one company
  • A company has one director
  • A director can be a director in several companies
  • A company can be managing several projects

I have imagined a URI design like this:

 GET  /projects
 GET  /projects/{id}
 GET  /projects/{id}/company
 GET  /projects/{id}/company/director
 PUT  /projects/{id}/company           # makes new/overwrite company
 POST /projects/{id}/company           # updates company
 PUT  /projects/{id}/company/director  # makes new/overwrite director
 POST /projects/{id}/company/director  # updates director

Would it be okay/user-friendly to have several URIs for the same resources, e.g.:

 POST /companies                       # makes a new company
 POST /companies/{id}                  # updates company
 GET  /companies/{id}
 POST /directors                       # makes a new director
 POST /directors/{id}                  # updates director
 GET  /directors/{id}

Is this good URI design according to best practices? What are pros and cons of above URI design?

preguntado el 31 de julio de 12 a las 12:07

1 Respuestas

The first form of URLs imply a tree structure where a company belongs to one and only one project, a director belongs to one and only one company. Is this the case?

If no, I'd prefer the second form of URLs. You hae all three resource types next to each other with no implied tree structure. Inside the resource representations you'd use links to navigate from a project to a company to a director.

Respondido 31 Jul 12, 12:07

No, companies can manage several projects, so your "flat" URI solution seems better. Would it be fine just to support "GET /projects/{1}/company" to reduce number of GETs? - Parnas

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