Can I remove the id/variable between parent and child Glue route URL?

muhammad.jadoon
muhammad.jadoon Spryker Solution Partner Posts: 7 🧑🏻‍🚀 - Cadet

https://docs.spryker.com/docs/scos/dev/glue-api-guides/202311.0/create-glue-api-resources-with-parent-child-relationships.html

After following the tutorial above, I get the following URL for my child resource:

https://glue-storefront.mysprykershop.com/module/1/bar.

is there a way to remove /1/ from the URL? Ideally, the url should be …/module/bar/…

Tagged:

Answers

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 86 🏛 - Council (mod)

    Bar belongs to an entity of Module, so there has to be an id.

    It's like:

    products/1/categories

    if you remove the productId then there isn't any parent reference to which those categories belong.

  • muhammad.jadoon
    muhammad.jadoon Spryker Solution Partner Posts: 7 🧑🏻‍🚀 - Cadet

    Thanks for your reply.

    What I am trying to do to have support for urls like this:

    deals/{dealsId}

    deals/regional/{regionId}

    I have a DealsResource which you can use to get specific deals. And then I have a RegionalResource which is child of DealsResource and I would like to have {regionId} in front of it without having a URL structure like deals/1/regional/{regionId}.

    Can you please tell me if this is possible?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,075 ⚖️ - Guardians (admin)

    Heyhey @muhammad.jadoon ,

    have a look at the getRouteProviderPlugins() method. (see https://github.com/spryker-shop/b2b-demo-shop/blob/202311.0/src/Pyz/Glue/GlueBackendApiApplication/GlueBackendApiApplicationDependencyProvider.php#L104) This method is available both for Glue Storefront API as well as for Glue Backend API. There you can add custom routes.

    To have a custom route for otherwise normal resource behaviour like you described it will likely would be a bit more ugly to implement to reuse existing functionality.

    Hope this helps.

    All the best,

    Florian

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,075 ⚖️ - Guardians (admin)

    Another idea, but not tested by myself:

    What happens if you define the resource-type as "deals/regional" and add this ResourcePlugin before the other one?

  • muhammad.jadoon
    muhammad.jadoon Spryker Solution Partner Posts: 7 🧑🏻‍🚀 - Cadet
  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 86 🏛 - Council (mod)
    edited March 1

    IMHO, What you are trying to obtain is a filtering.

    you can simply do it this way:

    https://glue-storefront.mysprykershop.com/deals?filter[deal.regionId]=2

    then in your DealReader

    public function getDealCollection(GlueRequestTransfer $glueRequestTransfer): GlueResponseTransfer
    {
    $filters = $glueRequestTransfer→getFilters();
    //apply filtering to your entities 
    }
    
    
    

    Creating a url like deals/regional/{regionId}. isn't a RESTFUL uri as there is no deal's id mapped to a region.

    I hope it helps the above mentioned solution.