Support for sub-resources in struts 2 rest plugin

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Support for sub-resources in struts 2 rest plugin

DevaGerald
Hi,

Sorry if i miss something here. As of my knowledge, the struts 2 rest plugin
supports only the following :
/resource - GET
/resource - POST
/resource/$resource_id - GET
/resource/$resource_id - PUT
/resource/$resource_id - DELETE

and also the custom methods like
/resource/$resource_id/my_custom_method - This will land me to the
respective custom method.

I need to write the following API pattern.

/resource/$resource_id/sub_resource/$sub_resource_id

Is this be supported? Plz help me with this.

Thanks and Regards,
Deva.



--
Sent from: http://struts.1045723.n5.nabble.com/Struts-User-f3426046.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Support for sub-resources in struts 2 rest plugin

Yasser Zamani-2


On 4/27/2018 11:45 AM, DevaGerald wrote:

> Hi,
>
> Sorry if i miss something here. As of my knowledge, the struts 2 rest plugin
> supports only the following :
> /resource - GET
> /resource - POST
> /resource/$resource_id - GET
> /resource/$resource_id - PUT
> /resource/$resource_id - DELETE
>
> and also the custom methods like
> /resource/$resource_id/my_custom_method - This will land me to the
> respective custom method.
>
> I need to write the following API pattern.
>
> /resource/$resource_id/sub_resource/$sub_resource_id
>
> Is this be supported? Plz help me with this.
>

As far as I see at [1], only the last slash location makes sense, so, it
seems no, this isn't supported.

However, in Struts REST plugin it seems resources are actions e.g.
"DELETE /resource/$resource_id" calls method "setId" of the action
"resource" with value "$resource_id" and then calls method "destroy".
It's up to you what do you write inside "destroy" method.

So, according to above paragraph, could you please describe what are you
trying to achieve with e.g. "DELETE
/resource/$resource_id/sub_resource/$sub_resource_id"? Because in Struts
REST plugin, "resource" and "sub_resource" will be evaluated as two
actions, not two master/child database records.

Regards.


[1]
https://github.com/apache/struts/blob/5ebd716fb7ffe10c6f1857c993285c63ab57f838/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java#L340

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Support for sub-resources in struts 2 rest plugin

DevaGerald
Thanks for your reply.

I am already using struts-2 rest plugin in production. What we are trying to
solve here, is a hierarchical resource entity API implementation.

Let me give an example of what I am trying to do.

For getting an organization info, we can use a REST API like
/organizations/organization_id,
whereas, to get an employee of an organization we need to map it as a
sub-resource like /organizations/organization_id/employees/employee_id
rather than just making it as /employees/employee_id.

Thanks & Regards,
Deva.



--
Sent from: http://struts.1045723.n5.nabble.com/Struts-User-f3426046.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Support for sub-resources in struts 2 rest plugin

Lukasz Lenart
This isn't supported right now. I think it would be good re-use
@Action annotation ro define a new (e.g. @Resource) to allow define
custom paths. Could you register a ticket?

2018-04-29 15:55 GMT+02:00 DevaGerald <[hidden email]>:

> Thanks for your reply.
>
> I am already using struts-2 rest plugin in production. What we are trying to
> solve here, is a hierarchical resource entity API implementation.
>
> Let me give an example of what I am trying to do.
>
> For getting an organization info, we can use a REST API like
> /organizations/organization_id,
> whereas, to get an employee of an organization we need to map it as a
> sub-resource like /organizations/organization_id/employees/employee_id
> rather than just making it as /employees/employee_id.
>
> Thanks & Regards,
> Deva.
>
>
>
> --
> Sent from: http://struts.1045723.n5.nabble.com/Struts-User-f3426046.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Support for sub-resources in struts 2 rest plugin

DevaGerald
I have created a new ticket.
https://issues.apache.org/jira/browse/WW-4935

Thanks,
Deva.



--
Sent from: http://struts.1045723.n5.nabble.com/Struts-User-f3426046.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Support for sub-resources in struts 2 rest plugin

DevaGerald
Any update on this requirement?
Or atleast any workaround?



--
Sent from: http://struts.1045723.n5.nabble.com/Struts-User-f3426046.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]