Is it possible to achieve with one sling service

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

09-03-2018

Just wonder if it is possible to achieve this.

I write a sling service called /wcmapi/myservice. I want to service to handle the URLs.

1. https://locahost:4502/wcmapi/myservice/myplan

2. https://locahost:4502/wcmapi/myservice/mycontact

3.https://locahost:4502/wcmapi/myservice/myhome

The service will take the last value (myplan or mycontact or myhome) in the url as input to generate different output. since the logic is very simple and output as well, instead creating an interface and implement three services, can I combine three services into one service and use the last value in the URL mimic as selector?

Let me know if it is feasible.

Thanks.

Replies

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

09-03-2018

I got it working. Can you please remove this topic. Thanks.

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

09-03-2018

Can you provide details on how you did this to help ppl looking to do this in the future.

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

13-03-2018

Define as this

@SlingServlet(paths={"/bin/myservice/home","/bin/myservice/contactus","/bin/myservice/yourplan"},

methods = "GET", metatype=true)

Use the last word as input variable. In this case, it is either home, or contactus or yourplan.

Avatar

Avatar

edubey

Avatar

edubey

edubey

13-03-2018

BigT168

Path is not recommended,

I am wondering why not use resource type and selector to differentiate the execution?

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

13-03-2018

do you mean

/bin/myservice.home

/bin/myservice.contactus

Avatar

Avatar

edubey

Avatar

edubey

edubey

13-03-2018

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

13-03-2018

I find this article "how to not use selector".

Sling: More About Selector Best Practices - Bots & AEM corner

Should I just create multiple services?

What's the best practice?

Avatar

Avatar

edubey

Avatar

edubey

edubey

14-03-2018

I looked at that article,

I don't think they are talking about not using selector but suggestion is when things gets complicated in one service, you can have multiple service to keep it simple.

But selector is the way to go.

Avatar

Avatar

BigT168

Avatar

BigT168

BigT168

14-03-2018

Thank you for the information. It is very helpful.

However, I really like the calling URL to be /bin/myservice/home instead /bin/myservice.home. Using sling selector, the URL becomes /bin/myservice.home.

Any suggestions?

Thank you.