[COMPLETE] An API for Open Brush #121
Replies: 3 comments 11 replies
-
Currently the API is asynchonous. You fire off a command and it gets queued. One command is popped off the queue at a time and executed (maximum one command per frame). This is nice and non-blocking but it means commands can't return values. I'd quite like the API to allow interogating the current state of the sketch so return values would be handy. I'm considering as a solution - every api call returns a handle (a guid). You can issue another request asking for the status of a command. This will either return "pending" or it will return some JSON with the return values. These commands alone would return synchonously. |
Beta Was this translation helpful? Give feedback.
-
I love this idea. Regarding the API itself... it's not particularly RESTful. Is invocation from a browser (which requires GETs) a key requirement? If not, I'd prefer something like What about GETting the current drawing or camera (I think those would be the two things that would be queried)? Is that a meaningful operation? General question that I don't know -- how similar is the current save file format to these type of APIs? Is it possible or desirable to unify them? |
Beta Was this translation helpful? Give feedback.
-
It wasn't really intended to be. I was aiming more for a kind of "RPC over HTTP" style. I'm not sure how much value REST (whatever one's interpretation of that rather nebulous concept is) would bring to this.
No but it does bring benefits. And if I were to abandon it, I'd want to hear what the downsides are. If we also want to accept simple formencoded POSTs then they are also basically a list of key-value pairs. So supporting GET doesn't really apply any additional restrictions. And it makes it really simple to use for people.
I think this is a shame and limits the potential audience for the API. (EDIT - actually point 2 is a bit confused. I realised what you were probably arguing for after I wrote this. See below)
Aren't you conflating two things? Once you've decided you like http://localhost:40074/api/v1/brush/draw then does it matter whether the parameters are in the query string or the request body? One isn't any more or less RESTful than the other. So we could use your style and not need curl or postman. The real distinction we seem to be discussing is whether the command (as distinct from the parameters) should be in the path vs the "key" of each key value pair. The advantage of my approach is that a single request can carry multiple commands. And again - this means that simple URLs and simple HTML forms can do more interesting stuff without needing javascript. |
Beta Was this translation helpful? Give feedback.
-
I've started a feature branch for a proposed API: https://github.com/ixxyxR/open-brush/tree/features/http-api
I'd like to note down some stuff here so people can chime in with their own thoughts.
Open Brush already listens for incoming http requests on port 40074 so it makes sense to reuse that.
I want the API to be simple enough that it can be used directly from the browser address bar without needing to write any javascript.
You should be able to just paste in URLs and see the results in your headset (or on your monitor - another goal is for this to be useful without VR)
It's also quite nice to be able to send multiple commands at once so I've gone with using query parameters as key value pairs.
Commands requiring more than one word to be clear use . as a seperator:
API commands that take multiple arguments are handled in ad hoc ways - the convention being a comma separated list:
There's a simple "turtle graphics" system and you can chain commands in a single url:
It accepts POST as well as GET:
I'll also accept some form of JSON. Maybe something like:
Beta Was this translation helpful? Give feedback.
All reactions