Loading ...
Sorry, an error occurred while loading the content.

PUTting an unnamed resource

Expand Messages
  • jlanng
    I m designing the interface of a system that stores and indexes documents (word docs etc). My intention is that the service should be human readable as well
    Message 1 of 4 , Jan 2, 2011
    • 0 Attachment
      I'm designing the interface of a system that stores and indexes documents (word docs etc). My intention is that the service should be human readable as well as easy to integrate programmatically - a resource-oriented REST interface would be perfect.

      Multiple documents in the same 'bucket' could have the same file name, so I an using a unique identifer in my URLs, e.g. GET /documents/sales/6543213

      Really, that resource should be uploaded by a corresponding PUT /documents/sales/6543213. However, I'm using a enterprise document management system behind that scenes which creates these identifiers, so the user cannot decide what their unique ID will be.

      I guess I could handle a PUT to /documents/sales/ and return a 301 to the new resource? Would that be the correct way to handle it?
    • mike amundsen
      ... If some other component is determining the URI, you should not be using PUT[1] at all. PUT assumes at complete (exact) URI and the operation
      Message 2 of 4 , Jan 13, 2011
      • 0 Attachment
        <snip>
        > Really, that resource should be uploaded by a corresponding PUT /documents/sales/6543213.  However, I'm using a enterprise document management system behind that scenes which creates these identifiers, so the user cannot decide what their unique ID will be.
        </snip>
        If some other component is determining the URI, you should not be
        using PUT[1] at all. PUT assumes at complete (exact) URI and the
        operation is idempotent (repeatable with the same basic results). If
        the "back-end" is creating the actual URIs on each "submit" then this
        is not a candidate for the HTTP PUT method. Instead, use POST and
        return "201 Created" w/ the URI that was "minted" by the component in
        the Location header.

        [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

        mca
        http://amundsen.com/blog/
        http://twitter.com@mamund
        http://mamund.com/foaf.rdf#me


        #RESTFest 2010
        http://rest-fest.googlecode.com




        On Sun, Jan 2, 2011 at 03:24, jlanng <james@...> wrote:
        > I'm designing the interface of a system that stores and indexes documents (word docs etc).  My intention is that the service should be human readable as well as easy to integrate programmatically - a resource-oriented REST interface would be perfect.
        >
        > Multiple documents in the same 'bucket' could have the same file name, so I an using a unique identifer in my URLs, e.g. GET /documents/sales/6543213
        >
        > Really, that resource should be uploaded by a corresponding PUT /documents/sales/6543213.  However, I'm using a enterprise document management system behind that scenes which creates these identifiers, so the user cannot decide what their unique ID will be.
        >
        > I guess I could handle a PUT to /documents/sales/ and return a 301 to the new resource?  Would that be the correct way to handle it?
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
      • Jørn Wildt
        Talking about 201 Created ... I just implemented that in a HTML forms page to make it easier (or, at least, clearer) for M2M interaction. Normally, on the
        Message 3 of 4 , Jan 13, 2011
        • 0 Attachment
          Talking about "201 Created" ... I just implemented that in a HTML forms page
          to make it easier (or, at least, clearer) for M2M interaction. Normally, on
          the HTML web, a successfull creation redirects uses "302 Found" which will
          send the browser to the newly created resource. Unfortunately the same
          doesn't happen with "201 Created" - the browser (FF and IE) ignores the
          Location header and stays on the same page.

          Have any of you found a good way around this issue?

          I decided to use "302 Found" instead and document that as the "Created"
          result.

          /Jørn

          ----- Original Message -----
          From: "mike amundsen" <mamund@...>
          To: "jlanng" <james@...>
          Cc: <rest-discuss@yahoogroups.com>
          Sent: Friday, January 14, 2011 1:17 AM
          Subject: Re: [rest-discuss] PUTting an unnamed resource


          <snip>
          > Really, that resource should be uploaded by a corresponding PUT
          > /documents/sales/6543213. However, I'm using a enterprise document
          > management system behind that scenes which creates these identifiers, so
          > the user cannot decide what their unique ID will be.
          </snip>
          If some other component is determining the URI, you should not be
          using PUT[1] at all. PUT assumes at complete (exact) URI and the
          operation is idempotent (repeatable with the same basic results). If
          the "back-end" is creating the actual URIs on each "submit" then this
          is not a candidate for the HTTP PUT method. Instead, use POST and
          return "201 Created" w/ the URI that was "minted" by the component in
          the Location header.

          [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

          mca
          http://amundsen.com/blog/
          http://twitter.com@mamund
          http://mamund.com/foaf.rdf#me


          #RESTFest 2010
          http://rest-fest.googlecode.com




          On Sun, Jan 2, 2011 at 03:24, jlanng <james@...> wrote:
          > I'm designing the interface of a system that stores and indexes documents
          > (word docs etc). My intention is that the service should be human readable
          > as well as easy to integrate programmatically - a resource-oriented REST
          > interface would be perfect.
          >
          > Multiple documents in the same 'bucket' could have the same file name, so
          > I an using a unique identifer in my URLs, e.g. GET
          > /documents/sales/6543213
          >
          > Really, that resource should be uploaded by a corresponding PUT
          > /documents/sales/6543213. However, I'm using a enterprise document
          > management system behind that scenes which creates these identifiers, so
          > the user cannot decide what their unique ID will be.
          >
          > I guess I could handle a PUT to /documents/sales/ and return a 301 to the
          > new resource? Would that be the correct way to handle it?
          >
          >
          >
          > ------------------------------------
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
        • mike amundsen
          Jørn: For 201 Created responses I usually return an entity body with the same link as the Location header. HTTP/1.1 201 Created Location:
          Message 4 of 4 , Jan 13, 2011
          • 0 Attachment
            Jørn:

            For "201 Created" responses I usually return an entity body with the
            same link as the Location header.

            HTTP/1.1 201 Created
            Location: http://example.com/resources/123
            Content-Type:text/html

            ...
            <a href="http://example.com/resources/123" rel="location">201 Created</a>
            ...

            Then clients (humans and/or scripts) can check out the Location header
            or look for the rel="location" link and act accordingly.

            I think I've used a <head><link rel="location" ... /> in the past, too.

            mca
            http://amundsen.com/blog/
            http://twitter.com@mamund
            http://mamund.com/foaf.rdf#me


            #RESTFest 2010
            http://rest-fest.googlecode.com




            On Fri, Jan 14, 2011 at 00:37, Jørn Wildt <jw@...> wrote:
            > Talking about "201 Created" ... I just implemented that in a HTML forms page
            > to make it easier (or, at least, clearer) for M2M interaction. Normally, on
            > the HTML web, a successfull creation redirects uses "302 Found" which will
            > send the browser to the newly created resource. Unfortunately the same
            > doesn't happen with "201 Created" - the browser (FF and IE) ignores the
            > Location header and stays on the same page.
            >
            > Have any of you found a good way around this issue?
            >
            > I decided to use "302 Found" instead and document that as the "Created"
            > result.
            >
            > /Jørn
            >
            > ----- Original Message ----- From: "mike amundsen" <mamund@...>
            > To: "jlanng" <james@...>
            > Cc: <rest-discuss@yahoogroups.com>
            > Sent: Friday, January 14, 2011 1:17 AM
            > Subject: Re: [rest-discuss] PUTting an unnamed resource
            >
            >
            > <snip>
            >>
            >> Really, that resource should be uploaded by a corresponding PUT
            >> /documents/sales/6543213. However, I'm using a enterprise document
            >> management system behind that scenes which creates these identifiers, so the
            >> user cannot decide what their unique ID will be.
            >
            > </snip>
            > If some other component is determining the URI, you should not be
            > using PUT[1] at all. PUT assumes at complete (exact) URI and the
            > operation is idempotent (repeatable with the same basic results). If
            > the "back-end" is creating the actual URIs on each "submit" then this
            > is not a candidate for the HTTP PUT method. Instead, use POST and
            > return "201 Created" w/ the URI that was "minted" by the component in
            > the Location header.
            >
            > [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6
            >
            > mca
            > http://amundsen.com/blog/
            > http://twitter.com@mamund
            > http://mamund.com/foaf.rdf#me
            >
            >
            > #RESTFest 2010
            > http://rest-fest.googlecode.com
            >
            >
            >
            >
            > On Sun, Jan 2, 2011 at 03:24, jlanng <james@...> wrote:
            >>
            >> I'm designing the interface of a system that stores and indexes documents
            >> (word docs etc). My intention is that the service should be human readable
            >> as well as easy to integrate programmatically - a resource-oriented REST
            >> interface would be perfect.
            >>
            >> Multiple documents in the same 'bucket' could have the same file name, so
            >> I an using a unique identifer in my URLs, e.g. GET /documents/sales/6543213
            >>
            >> Really, that resource should be uploaded by a corresponding PUT
            >> /documents/sales/6543213. However, I'm using a enterprise document
            >> management system behind that scenes which creates these identifiers, so the
            >> user cannot decide what their unique ID will be.
            >>
            >> I guess I could handle a PUT to /documents/sales/ and return a 301 to the
            >> new resource? Would that be the correct way to handle it?
            >>
            >>
            >>
            >> ------------------------------------
            >>
            >> Yahoo! Groups Links
            >>
            >>
            >>
            >>
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.