Extend standard REST service

Jan Mudrák asked on June 1, 2015 14:01

Hi,

is it possible to extend standard Kentico REST service (add new method)? We tried custom macro method (/rest/macro/{expression}), but it has some downfalls:

  • how to correctly pass parameters to macro
  • how to return object with correct binding

Thanks in advance for answer.

Correct Answer

Brenden Kehren answered on June 5, 2015 14:26

I don't believe you can modify the out of the box REST service code unless you have the source code license. So why not create your own web service that returns your JSON? This can easily be done.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on June 2, 2015 13:47

What are you trying to get from Kentico or what is your syntax? Where is it not working? You should be able to dynamically build your URL/querystring to accomplish what you need.

0 votesVote for this answer Mark as a Correct answer

Jan Mudrák answered on June 2, 2015 14:47

I am trying to display result of custom query - as stated in declined feature:

http://ideas.kentico.com/forums/239189-kentico-product-ideas/suggestions/4544022-rest-returning-custom-query-output

Regretfully, you can't write macro that will return list of objects (Macro resolver resolves them as strings - see http://localhost/rest/macro/RandomSelection("test",2)).

Therefore I want add separate method to RestService.svc. I have failed so far...

0 votesVote for this answer Mark as a Correct answer

Jan Mudrák answered on June 5, 2015 14:35

You are right. Developing separated REST service is the only way.

But I don't quite fully agree with opinion it can be quite easily done. If you want use all Kentico settings for REST, reuse databinding, authentication and authorization, you will have to make some development on your side...

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on June 5, 2015 18:44

Hello Jan,

It's possible to use macros with parameters with REST in Kentico but only under one condition:

  • It only works for macros that return a serializable result

Otherwise yes... you will need to develop a custom solution.

Regards, Martin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.