-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial REST api #18
initial REST api #18
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18 +/- ##
==========================================
+ Coverage 92.45% 92.82% +0.37%
==========================================
Files 11 11
Lines 464 516 +52
==========================================
+ Hits 429 479 +50
- Misses 35 37 +2 |
@jan-xyz this looks great, thanks! I will take me a bit of time to review, I'll update you soon. |
Yeah this looks like the way to go. I think we'll still need to start a session because otherwise a user calling e.g. Is there a particular reason why you direct all files to a single folder instead of on a per-request basis? Will this result in filename clashes even with We're on the right track though. When you finish this, it should make building a real front-end much, much easier. |
Regarding file storage/lifecycle: I imagine the whole thing to have an authentication mechanism in the future, including a guest mode. That would take care of file storage as well as lifecycle. You could possibly limit the storage space per user or leave it unlimited, and the guest just can upload one image at a time that gets overwritten by the next upload. I like the idea of reusing the same file for different visualisations, and it feels like a lot of overhead to re-upload these files over and over again. So, if we do it per-request we will certainly reduce the complexity but remove the possibility to re-use files. I am fine with both. All |
I agree, it makes more sense. Can you create the folders on a per-session basis and still get the same behavior? |
I don't see why this shouldn't be possible. I'll look into it and update the PR accordingly :) |
Hey @jan-xyz was out of town this weekend but saw the new commits coming in. Give me some time to look over it and I'll get back to you soon! |
No problem at all. I am looking forward to it. Note though that cookie/session based handling of the state is against REST as it means that the API isn't stateless. Once this is merged I would like to start working on a follow-up that brings it more in line with what REST means. That is:
That way we will be back on track for REST and it allows us to properly determine the life cycle of the files as well as separate users. The file used in the guest mode will be cleaned up directly after the request, the users will have a configurable amount of files they can upload and re-use |
Hey @jan-xyz, a bit embarrassing but I'm having trouble getting the And it's out of the scope of this PR, but maybe we should have custom 404 etc responses (right now it just dumps the raw html) in a future PR =) |
Sorry, I didn't update the examples. I brought the API more in line with the canonical way in a commit. Curl writes its own cookie and you can specify any cookie (e.g. I use example:
|
I pushed a couple changes to your PR. If you think they are good, go ahead and merge them and if not let me know! After that, I'll check it for code formatting/style and we can merge. Once again, great work =) |
improve handling of session
Wow, learned something new about flask again! :) Cheers for the improvement, I already thought it's weird to check the session before every request but couldn't come up with a better way. That decorator is really helpful! |
Ok just pushed a couple small additions. The only thing missing now is Then I see three things that need to be done (after the merge).
We'd be more than grateful if you want to continue working on these parts or anything else. Let me know your thoughts! |
doc strings and improved api message
I would suggest to put these all into separate PRs. This one is getting quite large now with 162 additions. |
This pull request adds the capability to have a JSON REST API discussed in #15 . I see it as a first step towards better URLs.
It doesn't touch upon the existing functionality. The only thing that was touched from the old code is the way that temporary directories for input and output files are created. They are no longer per visualisation request but per session with a session lasting a default of 31 days.
The functionality can be used with something like
curl
from the CLI or scripts/programs.There are 4 new URLs that can be used:
GET /api/
: right now it is only a placeholder. It could potentially be used to start a session to authenticate user and to display the API version.cmd:
curl "localhost:5000/api/"
output:
POST /api/images
: is used to upload images. It returns the filename and a UID in JSONcmd:
curl -F "file=@/path/to/image.png" localhost:5000/api/images -b /path/to/cookie -c /path/to/cookie
output:
GET /api/images
: lists all images uploaded via this APIcmd:
curl "localhost:5000/api/images" -b /path/to/cookie -c /path/to/cookie
output:
GET /api/visualize
: this page need to at least 2 argumentsimage=X
andvisualizer=X
.cmd:
curl "localhost:5000/api/visualize?image=0&visualizer=PartialOcclusion" -b /path/to/cookie -c /path/to/cookie
output:
All files referenced in the API can be directly accessed via the already existing URLs:
/inputs/<filename>
and/outputs/<filename>
EDIT: I changed the described API to represent the latest state of the branch which includes a consolidated path for listing and posting images which is according to the canonical way for resource management in REST and having the files being stored per session and not globally.