Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yaco Zaragoza 88 posts 363 karma points
    May 24, 2023 @ 17:54
    Yaco Zaragoza
    0

    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

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    May 25, 2023 @ 08:28
    Marc Goodson
    100

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies