Want to modify the request body and response body using rich python plugin

  1. Can I modify the request body and response body using python rich plugins?
    here, We can override the response body, but we want to modify the response body. In the Coprocess.MiniRequestObject, there is a body field, and it gives the body of the request and, I can’t modify the request body using this field as well.

  2. Can we paste the bundle inside the middleware/bundles of the tyk-gateway docker container rather than hosting in the webserver? If we can then can you give the configuration details?

  3. Can we configure the rich plugin for a particular endpoint? is there any way to do that ?

Hi cvaram!

I have some answers for you, but I need to do a quick consult with one of our developers first.

You can’t currently (in 2.8.x) modify the response via rich plugins. I know it’s coming in a future release, but I need to double-check what release it is.

I know that you can directly deploy, as you’re asking, but I’ll need to play with it a bit to give you proper advice on how to do that. You don’t even need to use a bundle directory if you deploy directory, you will be able to specify the path of the .py file directly.

For the third question, I think you will probably end up just writing the per-endpoint logic into the middleware, as these rich plugin middlwares are applied at the API level.

Let me verify all of this for you and I’ll get back to you soon!

Have a good day,
n.

1 Like

Thank you for the quick response @Nathan_Schepers

  1. I have asked about the modification of the request body as well.

“custom_middleware”: {
“pre”: [{
“name”: “MyPreMiddleware”,
“path”: “/opt/tyk-gateway/middleware/bundles/my-tyk-plugin/middleware.py”,
“require_session”: false
}],
“post”: [{
“name”: “MyPostMiddleware”,
“path”: “/opt/tyk-gateway/middleware/bundles/my-tyk-plugin/middleware.py”,
“require_session”: false
}],
“post_key_auth”: ,
“auth_check”: {
“name”:“MyAuthMiddleware”,
“path”:“/opt/tyk-gateway/middleware/bundles/my-tyk-plugin/middleware.py”,
“require_session”: false
},
“response”: ,
“driver”: “python”,
“id_extractor”: {
“extract_from”: “”,
“extract_with”: “”,
“extractor_config”: {}
}
}

I got an error like No hooks defined for API:. I don’t know whether this is the right configuration or not. Can you explain little bit further about this.
3. yeah, that is good. thanks for the reply

There is a PR for response middleware on Tyk’s GitHub, but I haven’t heard any update on it in awhile. An indication of when it can be released would be appreciated.