Some more work on the REST API documentation & set Location header on file upload response

This commit is contained in:
Gina Häußge 2014-03-24 22:50:56 +01:00
parent 072079df05
commit e373cde4f7
6 changed files with 66 additions and 41 deletions

View file

@ -16,17 +16,14 @@ Get connection settings
Retrieve the current connection settings, including information regarding the available baudrates and
serial ports and the current connection state.
**Example Request**
**Example**
.. sourcecode:: http
GET /api/connection HTTP/1.1
Host: example.com
Content-Type: application/json
X-Api-Key: abcdef...
**Example Response**
.. sourcecode:: http
HTTP/1.1 200 OK
@ -90,6 +87,10 @@ Issue a connection command
"autoconnect": true
}
.. sourcecode:: http
HTTP/1.1 204 No Content
**Example Disconnect Request**
.. sourcecode:: http
@ -103,6 +104,10 @@ Issue a connection command
"command": "disconnect"
}
.. sourcecode:: http
HTTP/1.1 204 No Content
:json string command: The command to issue, either ``connect`` or ``disconnect``
:json string port: ``connect`` command: The port to connect to. If left out either the existing ``portPreference``
will be used, or if that is not available OctoPrint will attempt auto detection. Must be part

View file

@ -18,14 +18,13 @@ Retrieve all files
Returns a :ref:`Retrieve response <sec-api-fileops-datamodel-retrieveresponse>`.
**Example request**:
**Example**:
.. sourcecode:: http
GET /api/files HTTP/1.1
Host: example.com
**Example response**:
X-Api-Key: abcdef...
.. sourcecode:: http
@ -84,14 +83,13 @@ Retrieve files from specific location
Returns a :ref:`Retrieve response <sec-api-fileops-datamodel-retrieveresponse>`.
**Example request**:
**Example**:
.. sourcecode:: http
GET /api/files/local HTTP/1.1
Host: example.com
**Example response**:
X-Api-Key: abcdef...
.. sourcecode:: http
@ -150,7 +148,7 @@ Upload file
Returns a :http:statuscode:`201` response with a ``Location`` header set to the management URL of the uploaded
file and an :ref:`Upload Response <sec-api-fileops-datamodel-uploadresponse>` as the body upon successful completion.
**Example request**
**Example**
.. sourcecode:: http
@ -186,13 +184,11 @@ Upload file
true
------WebKitFormBoundaryDeC2E3iWbTv1PwMC--
**Example response**
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: application/json
Location:
Location: http://example.com/api/files/sdcard/whistle_.gcode
{
"files": {
@ -247,14 +243,13 @@ Retrieve a specific file's information
On success, a :http:statuscode:`200` is returned, with a :ref:`file information item <sec-api-fileops-datamodel-fileinfo>`
as the response body.
**Example Request**
**Example**
.. sourcecode:: http
GET /api/files/local/whistle_v2.gcode HTTP/1.1
Host: example.com
**Example Response**
X-Api-Key: abcdef...
.. sourcecode:: http
@ -325,6 +320,10 @@ Issue a file command
"print": true
}
.. sourcecode:: http
HTTP/1.1 204 No Content
:param target: The target location on which to delete the file, either ``local`` (for OctoPrint's ``uploads``
folder) or ``sdcard`` for the printer's SD card (if available)
:param filename: The filename of the file for which to issue the command

View file

@ -46,6 +46,10 @@ Issue a job command
"command": "start"
}
.. sourcecode:: http
HTTP/1.1 204 No Content
**Example Restart Request**
.. sourcecode:: http
@ -59,6 +63,10 @@ Issue a job command
"command": "restart"
}
.. sourcecode:: http
HTTP/1.1 204 No Content
**Example Pause Request**
.. sourcecode:: http
@ -72,6 +80,10 @@ Issue a job command
"command": "pause"
}
.. sourcecode:: http
HTTP/1.1 204 No Content
**Example Cancel Request**
.. sourcecode:: http
@ -85,6 +97,10 @@ Issue a job command
"command": "cancel"
}
.. sourcecode:: http
HTTP/1.1 204 No Content
:json string command: The command to issue, either ``start``, ``restart``, ``pause`` or ``cancel``
:statuscode 204: No error
:statuscode 409: If the printer is not operational or the current print job state does not match the preconditions
@ -101,14 +117,13 @@ Retrieve information about the current job
Returns a :http:statuscode:`200` with a :ref:`sec-api-job-datamodel-response` in the body.
**Example Request**
**Example**
.. sourcecode:: http
GET /api/job HTTP/1.1
Host: example.com
**Example Response**
X-Api-Key: abcdef...
.. sourcecode:: http

View file

@ -22,7 +22,7 @@ Retrieve a list of available log files
Returns a :ref:`Logfile Retrieve response <sec-api-logs-datamodel-retrieveresponse>`.
**Example Request**
**Example**
.. sourcecode:: http
@ -30,8 +30,6 @@ Retrieve a list of available log files
Host: example.com
X-Api-Key: abcdef...
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK

View file

@ -65,6 +65,7 @@ Retrieve the current printer state
GET /api/printer?history=true&limit=2 HTTP/1.1
Host: example.com
X-Api-Key: abcdef...
.. sourcecode:: http
@ -146,6 +147,7 @@ Retrieve the current printer state
GET /api/printer?exclude=temperature,sd HTTP/1.1
Host: example.com
X-Api-Key: abcdef...
.. sourcecode:: http
@ -436,6 +438,7 @@ Retrieve the current tool state
GET /api/printer/tool?history=true&limit=2 HTTP/1.1
Host: example.com
X-Api-Key: abcdef...
.. sourcecode:: http
@ -585,6 +588,7 @@ Retrieve the current bed state
GET /api/printer/bed?history=true&limit=2 HTTP/1.1
Host: example.com
X-Api-Key: abcdef...
.. sourcecode:: http
@ -737,6 +741,7 @@ Retrieve the current SD state
GET /api/printer/sd HTTP/1.1
Host: example.com
X-Api-Key: abcdef...
.. sourcecode:: http

View file

@ -161,30 +161,33 @@ def uploadGcodeFile(target):
eventManager.fire(Events.UPLOAD, {"file": filename, "target": target})
files = {}
if done:
location = url_for(".readGcodeFile", target=FileDestinations.LOCAL, filename=filename, _external=True)
files.update({
FileDestinations.LOCAL: {
"name": filename,
"origin": FileDestinations.LOCAL,
"refs": {
"resource": location,
"download": url_for("index", _external=True) + "downloads/files/" + FileDestinations.LOCAL + "/" + filename
}
}
})
if sd and sdFilename:
location = url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFilename, _external=True)
files.update({
FileDestinations.LOCAL: {
"name": filename,
"origin": FileDestinations.LOCAL,
FileDestinations.SDCARD: {
"name": sdFilename,
"origin": FileDestinations.SDCARD,
"refs": {
"resource": url_for(".readGcodeFile", target=FileDestinations.LOCAL, filename=filename, _external=True),
"download": url_for("index", _external=True) + "downloads/files/" + FileDestinations.LOCAL + "/" + filename
"resource": location
}
}
})
if sd and sdFilename:
files.update({
FileDestinations.SDCARD: {
"name": sdFilename,
"origin": FileDestinations.SDCARD,
"refs": {
"resource": url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFilename, _external=True)
}
}
})
return make_response(jsonify(files=files, done=done), 201)
r = make_response(jsonify(files=files, done=done), 201)
r.headers["Location"] = location
return r
@api.route("/files/<string:target>/<path:filename>", methods=["GET"])