Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Can anyone point me to the documentation or provide me with a sample of what is the best way to create an API end point?
I am looking to pass our blog post to a separate site and would like for them to be able to just get the latest data (JSON) from a API end point
Hi Yaco
There are a couple of ways of achieving this
You could create an Alternate Template for the BlogPost and if DisableAlternativeTemplates is set to false in AppSettings, it means you can request any url of the site, and force it to use the alternative template instead of the selected template
So if you had a url:
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe
as a blog post, you could request that blog post via the alternative template using it's alias eg
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe?altTemplate=jsonOnly
(so your template would have alias 'jsonOnly'...
If you enabled the old 'ContentFinderByUrlAndTemplate' ContentFinder - https://github.com/umbraco/Umbraco-CMS/blob/e0d9084d04d667fda38908025eb181577ca7fa34/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs#L58
then this would also be routable via the Url
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe/jsonOnly
you'd then need to implement the template (you can route hijack with an alias matching the alt template) to render the JSON version of the blog post.
OR
You could create your own API Endpoint, and route it how you prefer by implementing an UmbracoApiController:
plenty of examples here:
https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers/
That would give you full control over the request and what is returned.
In Umbraco 12 there is this Content Delivery API everyone is going on about.... https://www.youtube.com/watch?v=CYdwW4DtK3o
regards
Marc
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
API end point?
Can anyone point me to the documentation or provide me with a sample of what is the best way to create an API end point?
I am looking to pass our blog post to a separate site and would like for them to be able to just get the latest data (JSON) from a API end point
Hi Yaco
There are a couple of ways of achieving this
You could create an Alternate Template for the BlogPost and if DisableAlternativeTemplates is set to false in AppSettings, it means you can request any url of the site, and force it to use the alternative template instead of the selected template
So if you had a url:
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe
as a blog post, you could request that blog post via the alternative template using it's alias eg
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe?altTemplate=jsonOnly
(so your template would have alias 'jsonOnly'...
If you enabled the old 'ContentFinderByUrlAndTemplate' ContentFinder - https://github.com/umbraco/Umbraco-CMS/blob/e0d9084d04d667fda38908025eb181577ca7fa34/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs#L58
then this would also be routable via the Url
https://www.mylovelysite/blogs/ten-exciting-things-you-wont-believe/jsonOnly
you'd then need to implement the template (you can route hijack with an alias matching the alt template) to render the JSON version of the blog post.
OR
You could create your own API Endpoint, and route it how you prefer by implementing an UmbracoApiController:
plenty of examples here:
https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers/
That would give you full control over the request and what is returned.
OR
In Umbraco 12 there is this Content Delivery API everyone is going on about.... https://www.youtube.com/watch?v=CYdwW4DtK3o
regards
Marc
is working on a reply...