|
1 |
| -vfs-http-adapter |
2 |
| -================ |
| 1 | +# HTTP Adapter |
| 2 | + |
| 3 | +This module is a connect/stack middleware module that wraps a vfs instance and |
| 4 | +serves it via a HTTP RESTful interface. |
| 5 | + |
| 6 | +The module is a setup function that creates a middleware instance. |
| 7 | + |
| 8 | +```js |
| 9 | +var root = "http://localhost:8080/rest/"; |
| 10 | + |
| 11 | +var vfs = require('vfs-local')({ |
| 12 | + root: process.cwd(), |
| 13 | + httpRoot: root, |
| 14 | +}); |
| 15 | + |
| 16 | +require('http').createServer(require('stack')( |
| 17 | + require('vfs-http-adapter')("/rest/", vfs) |
| 18 | +)).listen(8080); |
| 19 | + |
| 20 | +console.log("RESTful interface at " + root); |
| 21 | +``` |
| 22 | + |
| 23 | +## `HEAD /any/path` |
| 24 | + |
| 25 | +All HEAD requests are converted to GET requests internally and act identical, |
| 26 | +except there is an internal flag in the vfs layer telling it to not stream the body. |
| 27 | + |
| 28 | +## `GET /path/to/file` |
| 29 | + |
| 30 | +Serve a file to the client as a stream. Supports etags and range requests. |
| 31 | + |
| 32 | +## `GET /directory/path/with/slash/` |
| 33 | + |
| 34 | +Serve a directory listing as a JSON document. |
| 35 | + |
| 36 | +This is served as a streaming json document with a weak etag (since the order |
| 37 | +of the entries is not defined.) It supports conditional GET requests |
| 38 | + |
| 39 | +See `vfs.readdir` below for the format of the JSON. |
| 40 | + |
| 41 | +## `PUT /path/to/file` |
| 42 | + |
| 43 | +Recieve a file from the client and save it to the vfs. The file body is streamed. |
| 44 | + |
| 45 | +## `PUT /directory/path/with/slash/` |
| 46 | + |
| 47 | +Create a directory |
| 48 | + |
| 49 | +## `DELETE /path/to/file` |
| 50 | + |
| 51 | +Delete a file. |
| 52 | + |
| 53 | +## `DELETE /directory/path/with/slash/` |
| 54 | + |
| 55 | +Delete a directory (not recursive) |
| 56 | + |
| 57 | + |
| 58 | +## `POST /path/to/target` |
| 59 | + |
| 60 | +POST is used for various adhoc commands that are useful but don't fit well into |
| 61 | +the RESTful paradigm. The client sends a JSON body containing the request information. |
| 62 | + |
| 63 | +Currently this includes: |
| 64 | + |
| 65 | + - {"renameFrom": from} - rename a file from `from` to `target`. |
| 66 | + - {"copyFrom": from} - copy a file from `from` to `target`. |
| 67 | + - {"linkTo": data} - create a symlink at `target` containing `data`. |
3 | 68 |
|
4 |
| -A Restful front-end to a vfs instance |
|
0 commit comments