strapi-community / strapi-plugin-transformer

A plugin for Strapi Headless CMS that provides the ability to transform the API request or response.
https://market.strapi.io/plugins/strapi-plugin-transformer
MIT License
140 stars 22 forks source link

Transform response only for given API #62

Closed mighty-phoenix closed 1 year ago

mighty-phoenix commented 1 year ago

I want to transform the resopnse for a single particular API. How can I enable the plugin on that particular API, and leave the rest of the API responses as they are now? Quick help would be highly appreciated. Thanks! @ComfortablyCoding @cssmagic

ComfortablyCoding commented 1 year ago

With the current version the only way to do so is to send the Strapi-Transformer-Ignore header on all routes that you do not want the transforms to run.

Once the next version is released you can utilize the denyList config setting to opt out of all apis that the transformation should not run on.

mighty-phoenix commented 1 year ago

@ComfortablyCoding don't you think there should be a way to do it the opposite way also, i.e, mention which routes to work on? I have too many APIs being already used at many places. So I can't enable this change on my project, as it would lead to breaking changes, and sending the Strapi-Transformer-Ignore header everywhere Strapi APIs are being called is not a sane option in my case as you would imagine. Thanks!

ComfortablyCoding commented 1 year ago

Agreed, I will think about this a bit more to see optimal solution for both paradigms.

ComfortablyCoding commented 1 year ago

Support for both deny and allow list filtering has been released in v3

cc @mighty-phoenix

Montaser-BE commented 1 year ago

@ComfortablyCoding The deny list is not working. This is my configuration:


`transformer': {
     enabled: true,
     config: {
       prefix: '',
       responseTransforms: {
         removeAttributesKey: true,
         removeDataKey: true,
       },
       denyList: {
        'api::service.service': true,
      }
     }
   },
ComfortablyCoding commented 1 year ago

@Montaser-BE Please open a new issue outlining

And any other relevant debug info.