I am designing the rest apis that represent a file system.
File system support 3 functions
- mkdir(path)
- createFile(path, content) -> create if not exist and replace if exist.
- readFile(path)
Here is the REST API, I am thinking of designing what do you guys think of it ?
1. mkdir
POST v1/file-system/directories
BODY {
"path" : "???"
}
RESPONSE
{
"id" : "",
"path" "",
"files": [...] // this will contain info on files or directories under this directory
}
2. createFile
PUT v1/file-system/files
BODY {
"path" : "???"
"content": ""
}
RESPONSE
{
"id" : "",
"content": ""
"path" ""
}
3. read
GET v1/file-system/files/{file-path} or
GET v1/file-system/files?file-path={file-path}
RESPONSE
{
"id" : "",
"content": ""
"path" ""
}
Can you guys tell me if these API'S are correct representation for these function.
Few questions
- For GET API, shall I specify the path as path variable or query param ? If path then how will the backend differentiate between url path and file path. e.g. v1/file-system/files/a/b/c.txt
- Since create file can either create a file or replace the content of existing file, is it safe to use PUT ?
- For POST and PUT, do we specify path as path variable ?