Note that there are some explanatory texts on larger screens.

plurals
  1. POPOST to create a resource vs creating a new path element in REST
    primarykey
    data
    text
    <p>I'm trying to define a REST API on top of a MongoDB database where I should be able to add collections and documents. Assume the following:</p> <p><a href="http://games.mydomain.com/database/characters/123" rel="nofollow">http://games.mydomain.com/database/characters/123</a></p> <p>In MongoDB, I would have created the database, then the characters collection and finally the ironman document (which has an _id 123). The above record would have been created along these lines:</p> <pre><code> POST /database/characters/ HTTP/1.1 Host: games.mydomain.com Content-Type: application/json { "_id" : 123, "name" : "ironman" } </code></pre> <p>If later I realize that I should break the characters in two subcollections (i.e. friends and foes), I would create them after characters (don't worry about the migration part):</p> <pre><code> POST /database/characters/ HTTP/1.1 Host: games.mydomain.com Content-Type: application/json { "name" : "friends" } </code></pre> <p>and...:</p> <pre><code> POST /database/characters/ HTTP/1.1 Host: games.mydomain.com Content-Type: application/json { "name" : "foes" } </code></pre> <p>And here lies the problem: both POSTs (collection and document) look the same! That is, how would a developer differentiate one from the other when looking at the API? In this particular case, wouldn't be "better" (or less ambiguous) to write the API like so?:</p> <p><strong>To create a collection:</strong></p> <pre><code> POST /{database}/createCollection Host: games.mydomain.com {...} </code></pre> <p><strong>To create a document</strong></p> <pre><code> POST /{database}/{collection}/ Host: games.mydomain.com {...} </code></pre> <p>-or-</p> <pre><code> POST /{database}/{collection}/createDocument Host: games.mydomain.com {...} </code></pre> <p>I know it's not REST-like, but the API has to create resources <em>and</em> intermediate paths (i.e. collections). Any idea how could I approach this problem?</p> <p>Thanks in advance!</p> <p>-- Tito</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload