What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello guys, Is there a way to define custom glue api url like orders/:orderId/details/:addressId? +o

U03GZT3EN85 Posts: 6 🧑🏻‍🚀 - Cadet

Hello guys, Is there a way to define custom glue api url like orders/:orderId/details/:addressId?
+orderId, addressId is path variable

I check spryker document but can't find any article related to this feature.
Thanks in advance


  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer

    It's a little bit more complex in Glue.

    You can add custom routes by implementing a new *RoutePlugin to \Pyz\Glue\GlueApplication\GlueApplicationDependencyProvider::getResourceRoutePlugins which implements the \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRoutePluginInterface .

    The \Spryker\Glue\AuthRestApi\Plugin\AccessTokensResourceRoutePlugin::getResourceType will determine what the path looks like (return 'orders' in your example).
    Pathvariables can't be named for using the name in the code, but are automatically mapped and can be accessed in the controller via \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface::getResource()->getId() as the first argument injected into each controller action is the RestRequestInterface .

    To build more complex routes like in your example you can chain them implementing the \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceWithParentPluginInterface . Which will give you the possibility to access the orders resource in your details controller action by using \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface::findParentResourceByType('orders')->getId() .

    All this is more ore or less documented at https://docs.spryker.com/docs/scos/dev/glue-api-guides/202204.0/glue-infrastructure.html

    If you want to have the names of your parameters in your OpenAPI documentation, you can do so by using the right annotation to document your controller action. An example can be found at https://github.com/spryker/customers-rest-api/blob/master/src/Spryker/Glue/CustomersRestApi/Controller/AddressResourceController.php#L87. The whole documentation topic for glue is documented at https://docs.spryker.com/docs/scos/dev/tutorials-and-howtos/introduction-tutorials/glue-api/documenting-glue-api-resources.html

  • U03GZT3EN85
    U03GZT3EN85 Posts: 6 🧑🏻‍🚀 - Cadet

    Thank you @UL6DGRULR