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
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
Comments
-
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 theRestRequestInterface
.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
0 -
Thank you @UL6DGRULR
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random