Ticket #118: webapi.warner1.diff

File webapi.warner1.diff, 6.5 KB (added by warner, at 2007-08-23T19:41:42Z)

my proposed changes to the new version

  • webapi-new.txt

    old new  
    1919"ssl:8011:privateKey=mykey.pem:certKey=cert.pem" would run an SSL server. See
    2020twisted.application.strports for more details.
    2121
    22 If $NODEDIR/webpassword exists, it will be used (somehow) to require HTTP
    23 Digest Authentication for all webserver connections.  XXX specify how
    24 
    2522b. file names
    2623
    2724The node provides some small number of "virtual drives". In the 0.5
     
    5855
    5956c. URIs
    6057
     58From the "URIs" chapter in architecture.txt, recall that each file and
     59directory has a unique "URI". This is a string which provides a secure
     60reference to the file or directory: if you know the URI, you can retrieve
     61(and possibly modify) the object. If you don't know the URI, you cannot
     62access the object.
     63
    6164A separate top-level namespace ("uri/" instead of "vdrive/") is used to
    6265access to files and directories directly by URI, rather than by going through
    63 the vdrive.
     66the pathnames in the vdrive.
    6467
    6568For example, this identifies a file or directory:
    6669
     
    7275http://localhost:8011/uri/$URI/Pictures/tractors.jpg
    7376
    7477In the following examples, "$URL" is a shorthand for a URL like the ones
    75 above, either with "vdrive/" as the top level and a sequence of
    76 slash-separated pathnames following, or with "uri/" as the top level,
    77 followed by a URI, optionally followed by a sequence of slash-separated
    78 pathnames.
     78above, either with "vdrive/" and a vdrive name as the top level and a
     79sequence of slash-separated pathnames following, or with "uri/" as the top
     80level, followed by a URI, optionally followed by a sequence of
     81slash-separated pathnames.
    7982
    8083Now, what can we do with these URLs? By varying the HTTP method
    8184(GET/PUT/POST/DELETE) and by appending a type-indicating query argument, we
     
    8689  GET $URL?t=json
    8790
    8891  This returns machine-parseable information about the indicated file or
    89   directory in the HTTP response body. This information contains a flag that
    90   indicates whether the thing is a file or a directory.
     92  directory in the HTTP response body. The JSON always contains a list, and
     93  the first element of the list is always a flag that indicates whether the
     94  referenced object is a file or a directory.
    9195
    9296  If it is a file, then the information includes file size and URI, like
    9397  this:
     
    127131  response.
    128132
    129133  If the indicated object a directory, then this returns an HTML page,
    130   intended to be used by humans, which contains HREF links to all files and
    131   directories reachable from this directory. These HREF links do not have a
    132   t= argument, meaning that a human who follows them will get pages also
    133   meant for a human. It also contains forms to upload new files, and to
    134   delete files and directories. These forms use POST methods to do their job.
     134  intended to be displayed to a human by a web browser, which contains HREF
     135  links to all files and directories reachable from this directory. These
     136  HREF links do not have a t= argument, meaning that a human who follows them
     137  will get pages also meant for a human. It also contains forms to upload new
     138  files, and to delete files and directories. These forms use POST methods to
     139  do their job.
    135140
    136141  You can add the "save=true" argument, which adds a 'Content-Disposition:
    137142  attachment' header to prompt most web browsers to save the file to disk
    138143  rather than attempting to display it.
    139144
    140   A filename (from which a MIME type can be derived) can be specified using a
    141   'filename=' query argument. This is especially useful if the $URL does not
    142   end with the name of the file (because it instead ends with the identifier
    143   of the file). This filename is also the one used if the 'save=true'
    144   argument is set. For example:
     145  A filename (from which MIME type can be derived, for use in the
     146  Content-Type header) can be specified using a 'filename=' query argument.
     147  This is especially useful if the $URL does not end with the name of the
     148  file (e.g. if it ends with the URI of the file instead). This filename is
     149  also the one used if the 'save=true' argument is set. For example:
    145150
    146151   GET http://localhost:8011/uri/$TRACTORS_URI?filename=tractors.jpg
    147152
     
    176181
    177182  The URI of the child is provided in the body of the HTTP request.
    178183
    179   There is an optional "?overwrite=" param whose value can be "true", "t",
    180   "1", "false", "f", or "0" (case-insensitive), and which defaults to "true".
    181   If the indicated directory already contains the given child name, then if
    182   overwrite is true then the value of that name is changed to be the new URI.
    183   If overwrite is false then an error is returned. XXX specify the error
     184  There is an optional "?replace=" param whose value can be "true", "t", "1",
     185  "false", "f", or "0" (case-insensitive), and which defaults to "true". If
     186  the indicated directory already contains the given child name, then if
     187  replace is True then the value of that name is changed to be the new URI.
     188  If replace is False then an HTTP 409 "Conflict" error is returned.
    184189
    185190  This can be used to attach a shared directory (a directory that other
    186191  people can read or write) to the vdrive. Intermediate directories, if any,
     
    203208  they can continue to access the resource through the URI. Only if a person
    204209  is not in possession of the URI, and they do not have access to any
    205210  directories which contain names pointing to this resource, are they
    206   prevented from accessing the resource.
     211  prevented from accessing the resource. (this behavior is very similar to
     212  the way hardlinks and anonymous files work in traditional unix
     213  filesystems).
    207214
    2082152. convenience methods
    209216
     
    221228  the client is not obligated to do anything with the URI. According to the
    222229  HTTP/1.1 specification (rfc2616), this should return a 200 (OK) code when
    223230  modifying an existing file, and a 201 (Created) code when creating a new
    224   file.
     231  file. (TODO: as of 0.5, the web server only returns 200, never 201).
    225232
    226233  To use this, run 'curl -T localfile http://localhost:8011/vdrive/global/newfile'
    227234
     
    260267If your recursive algorithm uses the uri of the child instead of the name of
    261268the child, then those kinds of mistakes just can't happen. Note that both the
    262269child's name and the child's URI are included in the results of listing the
    263 parent directory, so it isn't harder to use the URI for this purpose.
     270parent directory, so it isn't any harder to use the URI for this purpose.
    264271
    265272In general, use names if you want "whatever object (whether file or
    266273directory) is found by following this name (or sequence of names) when my