syncthing/syncthing — pull request #723 by Nutomic (2014-09-21 23:02:20+00:00)
Title: [do not merge] API functions for file access

This can be used to implement a web interface like Dropbox has it, so files can be accessed from a device that does not have syncthing installed itself. Personally, I want to implement a [DocumentsProvider](https://developer.android.com/guide/topics/providers/document-provider.html) for Android. The next step (after the Android implementation) would be to get all file data from `Model`, so that files are downloaded on the fly, and local storage is not needed (but I didn't understand the code good enough for that).

**/rest/file/create/**
Creates new file or directory at the given path. To create a directory, pass a trailing '/'. Note that the parent directory must already exist.
(We might also get rid of this and just use `/rest/file/write/`, but I put it in because I was going by the Android API)
`curl -s "http://localhost:8081/rest/file/create?repo=default&path=testfile"`

**/rest/file/delete/**
Deletes the given file. If it is a directory, it has to be empty.
`curl -s "http://localhost:8081/rest/file/delete?repo=default&path=testfile"`

**/rest/file/write/**
Uploads and replaces the file. Must exist.
`curl -s "http://localhost:8081/rest/file/write?repo=default&path=testfile" -H "X-API-Key: xyz" --form "file=@testfile"`

**/rest/file/read/**
Downloads the file. Must exist.
curl -s "http://localhost:8081/rest/file/read?repo=default&path=testfile"

**/rest/file/list**
Lists all directory contents.
```
curl -s "http://localhost:8081/rest/file/list?repo=default"
[ {
"mime" : "text/plain; charset=utf-8",
"modified" : "1411333357",
"name" : "file.txt",
"size" : "0"
}]
```

There's lots of duplicate code (mostly error handling), I'll see how I can improve that (open for suggestions).

I'm not quite sure how the CSRF works, it seems that only `POST` requests are protected? (at least that's how it seemed during my debugging)

At the moment, there's no client for this (except for the curls above). You might want to wait until I implement this on Android before merging (I might also have to change stuff for that).

Sorry for this wall of text :D