# Plugin server cannot accept body with get request from plugin ui

**URL:** <https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [November 22, 2023, 11:04am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721 "2023-11-22T11:04:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [November 22, 2023, 11:04am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/1 "2023-11-22T11:04:15Z")

</div>

Hi,

I am developing a custom external plugin in React, on Kibana 8.8.1.

When I give a GET request from plugin ui to server, with a body; the body is still always undefined, even if I validate it with the basic schema. I do get params and query params.

Reference: [External Kibana Server Plugin Get Route request.body is Always An Empty Object](https://discuss.elastic.co/t/external-kibana-server-plugin-get-route-request-body-is-always-an-empty-object/297638) (similar post)

Thanks

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [November 22, 2023, 9:55pm UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/2 "2023-11-22T21:55:47Z")

</div>

cc @afharo could we please get some eyes on this?

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [November 27, 2023, 5:14am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/3 "2023-11-27T05:14:00Z")

</div>

Hi,

Can anyone give some input on this?

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [November 29, 2023, 12:04am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/4 "2023-11-29T00:04:08Z")

</div>

Apologies for the delay.

It is a current limitation in Kibana: `HEAD` and `GET` requests don't support body payloads: [https://github.com/elastic/kibana/blob/e4816c66abab94ee47d026781a94dcfa57021554/packages/core/http/core-http-router-server-internal/src/router.ts#L107-L117](https://github.com/elastic/kibana/blob/e4816c66abab94ee47d026781a94dcfa57021554/packages/core/http/core-http-router-server-internal/src/router.ts#L107-L117)

As explained [here](https://stackoverflow.com/a/983458), it goes against the HTTP specs. If you are designing an API that needs a body, you should use any of the other methods available `POST`, `PUT`, `PATCH`.

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [November 29, 2023, 10:50am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/5 "2023-11-29T10:50:48Z")

</div>

Hi Alejandro,

Hope you are doing well.

Thanks for the clarification.

Actually, I have another Backend server. So the flow of api call/data is from PLUGIN UI -\> PLUGIN SERVER -\> BACKEND SERVER -\> DB and vice versa.

So for some get requests, I need to pass a body from UI to server, and that's the reason I asked for the clarification. As you said, Body is not accepted from PLUGIN UI -\> PLUGIN SEFVER GET request, but from PLUGIN SERVER -\> Backend, I am able to pass body with GET request.

Now that I know by default, Kibana doesn't allow body with GET requests from plugin ui to server; I was thinking of the below flow.

PLUGIN UI -\> PLUGIN SRRVER (all requests will be a POST request, within the body, I will pass method (which can be get, post, put, delete, ...) and the data .

```auto
{
    method: 'GET',
    data: {...}
}

```

So in PLUGIN SERVER, all routes will be post, within which it will check the method attribute passed within the body, and then accordingly makes that request to Backend server.

Eg: We want to GET the list of book, returning only the fields id and name.

_PLUGIN UI -\> PLUGIN SERVER_

```auto
const body = {
    method: 'GET',
    data: {
        fields: ['id', 'name']
    }
};
axios.post(url, body);

```

  

_PLUGIN SERVER -\> BACKEND SERVER_

```auto
router.post(
    {
        path: .....,
        validate: {
            body: {
                method: schema.string(),
                data: schema.maybe(schema.any())
            }
        }
    }
),
async(context, request, response) => {
    const backend_url = '.....';
    const resp = await axios({
        method: request.body.method,
        backend_url,
        data: request.body.data
    }
    .......
}

```

Is this way of api calling fine?

Thanks

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [November 29, 2023, 5:29pm UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/6 "2023-11-29T17:29:15Z")

</div>

If I'm understanding correctly, you're building something similar to a proxy from the Kibana UI to another backend.

In that case, I think your approach is correct.

In general, servers should not expose the underlying backend implementations and a proper restful API should be designed without passing the complexity of the underlying backend to the UI logic.

Like, assuming the backend service handles students, you could expose the `GET` methods `GET /api/students` and `GET /api/students/:id`, and internally do any other type of calls to the backend if needed.

However, for a quick prototype, I think it's fine to initially have the backend "know-how" in the UI.

TL;DR, your solution should work.

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [November 30, 2023, 6:45am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/7 "2023-11-30T06:45:37Z")

</div>

Thanks a lot for you response Alejandro 😀

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 28, 2023, 6:45am UTC](https://discuss.elastic.co/t/plugin-server-cannot-accept-body-with-get-request-from-plugin-ui/347721/8 "2023-12-28T06:45:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
