diff --git a/README.md b/README.md index 1a0c85a..fe711e0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It provides a simple Grafana 7.x panel that shows only one button - to integrate with any kind of HTTP/REST API: -* Support `GET` and `POST` HTTP verb +* Support `GET`, `POST`, `PUT`, `PATCH` and `DELETE` HTTP verb * Adds no new javascript dependencies * Uses standard browser APIs and respects CORS * Optional text payload for `POST` requests via syntax-highlighiting editor @@ -14,7 +14,7 @@ It provides a simple Grafana 7.x panel that shows only one button - to integrate * Variable support via `$variableName` in * URL * Header/Query parameter name & value - * POST body payload + * POST/PUT/PATCH body payload * Button label * Support for HTTP Basic Auth * Custom label text & Grafana template design @@ -38,7 +38,7 @@ Due to the Grafana API & security restrictions in modern browsers the following * Neither username nor password are stored encryted in Grafana. The password is there to everyone with access to the dashboard in Grafana! * The *server* at the URL _must_ provide proper resposne to the [CORS pre-flight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request). That is: - * Provide a proper response to the `OPTIONS` request performed by the browser before the actual `GET`/`POST` requiest is issued + * Provide a proper response to the `OPTIONS` request performed by the browser before the actual `GET`/`POST`/`PUT`/`PATCH`/`DELETE` request is issued * Provide a [`Access-Control-Allow-Credentials: true`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials) header * Provide a proper [`Access-Control-Allow-Origin`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin) header. _No wildcards_ are allowed if credentials are used! diff --git a/src/ButtonPanel.tsx b/src/ButtonPanel.tsx index 67fe5fd..e473099 100644 --- a/src/ButtonPanel.tsx +++ b/src/ButtonPanel.tsx @@ -106,7 +106,7 @@ export class ButtonPanel extends PureComponent { //referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url }; - if (options.method === 'POST') { + if (options.method === 'POST' || options.method == 'PUT' || options.method == 'PATCH') { requestHeaders.set('Content-Type', options.contentType); if (options.payload) { fetchOpts.body = this.interpolateVariables(options.payload); diff --git a/src/module.ts b/src/module.ts index d481b44..ff7fdea 100644 --- a/src/module.ts +++ b/src/module.ts @@ -24,6 +24,14 @@ export const plugin = new PanelPlugin(ButtonPanel).setPanelO value: 'POST', label: 'POST', }, + { + value: 'PUT', + label: 'PUT', + }, + { + value: 'PATCH', + label: 'PATCH', + }, { value: 'DELETE', label: 'DELETE', @@ -82,7 +90,7 @@ export const plugin = new PanelPlugin(ButtonPanel).setPanelO { label: 'text/plain', value: 'text/plain' }, ], }, - showIf: (config) => config.method === 'POST', + showIf: (config) => (config.method === 'POST' || config.method == 'PUT' || config.method == 'PATCH'), }) .addCustomEditor({ id: 'payload', @@ -103,7 +111,7 @@ export const plugin = new PanelPlugin(ButtonPanel).setPanelO } }, }, - showIf: (config) => config.method === 'POST', + showIf: (config) => (config.method === 'POST' || config.method == 'PUT' || config.method == 'PATCH'), editor: ButtonPayloadEditor, }) .addSelect({