Copied to clipboard

Flag this post as spam?

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


  • Predrag Andrejević 10 posts 81 karma points
    Oct 02, 2019 @ 13:35
    Predrag Andrejević
    1

    Creating Web API that returns JSON

    Hello

    I need to build Umbraco Web API that will return JSON containing values of created document types, but I can't find any clear explanation on how to do so. I'm relatively new to APIs and I don't know if I need to provide anything else (if I do, please say so and I will). Thanks in advance!

  • Magnus Eriksson 103 posts 241 karma points
    Oct 02, 2019 @ 14:41
    Magnus Eriksson
    0

    You basically write a regular/standard .Net Web Api but inherit from UmbracoApiController instead of ApiController and the routing/url to the Api will be ~/Umbraco/Api/[YourControllerName].

    See more info here: https://our.umbraco.com/documentation/reference/routing/webapi/

    Regards, Magnus

  • Predrag Andrejević 10 posts 81 karma points
    Oct 03, 2019 @ 11:52
    Predrag Andrejević
    0

    Thank you for answering. Problem was that I was using VS Code. When I switched to VS everything went smoothly, but now I don't know how to get Document Types for CRUD methods. If you know how to do that, please help me.

  • Magnus Eriksson 103 posts 241 karma points
    Oct 03, 2019 @ 13:08
    Magnus Eriksson
    0

    Talking in general terms you would for reading Umbraco data use the Umbraco helper since it's cached. See https://our.umbraco.com/documentation/Reference/Querying/UmbracoHelper/. Typically:

    IPublishedContent content = Umbraco.Content(id);
    

    For create, update, delete you would have to look at the different services available: https://our.umbraco.com/documentation/Reference/Management/Services/

    Regards, Magnus

  • Connie DeCinko 95 posts 224 karma points
    Oct 02, 2019 @ 15:01
    Connie DeCinko
    0

    What I haven't found is how you get the properties of the document type as JSON. I can easily create an API end point in Umbraco that returns a static string. Other than looking at some of Matt's code, there appears to be no documentation beyond the creation of a simple end point.

    With Umbraco Headless not out yet, needing to wait until the x.1 version is out and stable, and the downside of it not working on prem, we need better documentation to create our own headless that can compete with the other open source solutions.

  • Magnus Eriksson 103 posts 241 karma points
    Oct 02, 2019 @ 15:09
    Magnus Eriksson
    0

    My experience is that to return json from a Web Api using Umbraco is no different from a standard .Net Web Api, i.e.: https://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome

    The only part that I know of that is different is the routing, otherwise I write my .Net Web Apis using Umbraco the same I would when not using Umbraco.

    Regards, Magnus

Please Sign in or register to post replies

Write your reply to:

Draft