-
-
Notifications
You must be signed in to change notification settings - Fork 39
apis
The extension can run one more REST API hosts.
This can be useful, if something should control an editor from remote, e.g. a build operation, which runs on a server, shows a popup, when its done.
A list of endpoints (with examples) can be found here.
{
"deploy.reloaded": {
"apis": {
"80": {
"allowed": [
"192.168.0.0/24",
"0:0:0:0:0:ffff:c0a8:0/24"
],
"users": {
"mkloubert": "P@ssword123!"
}
}
}
}
}
Name | Description |
---|---|
allowed |
One or more allowed IP addresses in CIDR format. |
autoStart |
Auto start host or not. Default: (true)
|
description *
|
A description for the host. |
endpoints |
A list of one or more custom endpoints to define. |
name *
|
A (display) name for the host. |
realm *
|
The custom name of the real for basic authentification. Default: vscode-deploy-reloaded API
|
ssl |
Settings for secure HTTP. |
useBuildIn |
Use build-in endpoints or not. Default: (true)
|
users |
One or more user to define. |
* supports placeholders
{
"deploy.reloaded": {
"apis": {
"443": {
"ssl": {
"cert": "./cert.pem",
"key": "./key.pem"
}
}
}
}
}
Name | Description |
---|---|
ca *
|
The path to the ca file. |
cert *
|
The path to the file of the certificate. |
key *
|
The path to the key file. |
passphrase |
The required password for the key file. |
rejectUnauthorized |
Request unauthorized or not. Default: (true)
|
* supports placeholders
Relative paths are mapped to the .vscode
folder or the sub folder .vscode-deploy-reloaded
inside the user's home directory.
{
"deploy.reloaded": {
"apis": {
"443": {
"users": {
"mk": "P@assword!123",
"tm": {
"password": "@notherPassword123!"
}
}
}
}
}
}
Name | Description |
---|---|
isActive |
Is user active or not. Default: (true)
|
password |
The password to use. |
Returns general information.
GET /api HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 324
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"host": {
"os": "win32"
},
"me": {
"address": "::ffff:127.0.0.1",
"port": 5979
},
"message": "OK",
"vscode": {
"eol": "\r\n",
"name": "Visual Studio Code",
"node": {
"v8": "5.8.283.38",
"version": "7.9.0"
},
"version": "1.21.1"
}
}
Returns a list of all commands.
GET /api/commands HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 120
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": [
"editor.action.selectAll",
"git.pull"
]
}
Executes a command.
GET /api/commands/editor.action.selectAll HTTP/1.1
Host: localhost
HTTP/1.1 204 No Content
X-Powered-By: Express
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
Returns a list of all editors.
GET /api/editors HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 233
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": [
{
"index": 0,
"isActive": true,
"document": {
"eol": "\r\n",
"file": {
"name": "ltotm.txt",
"path": "c:\\my-project"
},
"isDirty": false,
"isUntitled": false,
"language": "jsonc",
"lines": 39,
"resources": {
"_self": "/api/editors/0",
"content": "/api/editors/0/content"
},
"version": 1
}
}
]
}
Opens a new text editor (with content).
POST /api/editors HTTP/1.1
Host: localhost
Lorem ipsum
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 277
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": {
"index": 0,
"isActive": true,
"document": {
"eol": "\r\n",
"file": {
"name": "Untitled-1"
},
"isDirty": true,
"isUntitled": true,
"language": "json",
"lines": 4,
"resources": {
"_self": "/api/editors/0",
"content": "/api/editors/0/content"
},
"version": 1
}
}
}
Returns information about an editor.
GET /api/editors/0 HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 231
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": {
"index": 0,
"isActive": true,
"document": {
"eol": "\n",
"file": {
"name": "ltotm.txt",
"path": "/home/mkloubert/my-project"
},
"isDirty": false,
"isUntitled": false,
"language": "jsonc",
"lines": 39,
"resources": {
"_self": "/api/editors/0",
"content": "/api/editors/0/content"
},
"version": 1
}
}
}
Returns the content of an editor.
GET /api/editors/0/content HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: text/plain; charset=utf-8
X-Vscode-Deploy-Reloaded-Lang: plaintext
Content-Length: 889
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Returns a list of all extensions.
GET /api/extensions HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 11790
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": [
{
"id": "bmewburn.vscode-intelephense-client",
"index": 0,
"isActive": false,
"path": "C:\\Users\\houbi\\.vscode\\extensions\\bmewburn.vscode-intelephense-client-0.8.8"
},
{
"id": "christian-kohler.path-intellisense",
"index": 1,
"isActive": true,
"path": "C:\\Users\\houbi\\.vscode\\extensions\\christian-kohler.path-intellisense-1.4.2"
}
]
}
Returns a list of all languages.
GET /api/languages HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
X-Powered-By: Express
Content-type: application/json; charset=utf-8
Content-Length: 598
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"success": true,
"code": 0,
"message": "OK",
"data": [
"csharp"
"typescript"
"xml"
]
}
Opens a new tab of a parsed Markdown document.
POST /api/markdown HTTP/1.1
Host: localhost
{
"title": "My Document",
"content": "# Header 1\n\nLorem ipsum",
"options": {
"css": "body { background-color: red; }"
}
}
HTTP/1.1 204 No Content
X-Powered-By: Express
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
Shows a popup in the remote editor.
POST /api/messages HTTP/1.1
Host: localhost
{
"message": "Test message",
"type": "error"
}
Possible values for type
, which is optional, are:
-
e
,err
,error
-
i
,info
,information
-
w
,warn
,warning
HTTP/1.1 204 No Content
X-Powered-By: Express
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
Writes text to the output channel of the extension.
PUT /api/output HTTP/1.1
Host: localhost
Lorem ipsum
HTTP/1.1 204 No Content
X-Powered-By: Express
Date: Wed, 5 Sep 1979 23:09:00 GMT
Connection: keep-alive
{
"deploy.reloaded": {
"apis": {
"80": {
"endpoints": {
"my_endpoint": {
"methods": [ "GET", "POST" ],
"script": "./api.my_endpoint.js",
"options": 5979
}
}
}
}
}
}
Name | Description |
---|---|
methods |
A list of one or more allowed HTTP methods. Default: all |
options |
Options for the script. |
script |
The path to the script to execute. Relative paths will be mapped to the .vscode subfolder or the .vscode-deploy-reloaded folder inside the user's home directory. |
The endpoint in the upper example will be available via /api/my_endpoint
. Have a look at the article Routing to get to known, how to define routes via Express.
The script ./api.my_endpoint.js
should look like that:
exports.GET = async function(args, request, response) {
response.setHeader('Content-type', 'application/json; charset=utf-8');
return response.status(200).send(new Buffer(
JSON.stringify({
'test': 23979 + args.options
}),
'utf8'
));
};
exports.POST = async function(args, request, response) {
const Helpers = args.require('./helpers');
const BODY = await Helpers.readAll( request );
// TODO
return response.status(204)
.send();
};
Each HTTP method is handled by a public / exported function, with the name of the method in upper case.
If you want to handle any (other) HTTP method, you have to implement a request()
function:
exports.request = async function(args, request, response) {
// HTTP method is stored in 'request.method'
};
args
implements the ApiEndpointArguments interface.
request
and response
parameters are the same, as defined in the Express API.