Copied to clipboard

Flag this post as spam?

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


  • keilo 568 posts 1023 karma points
    Nov 06, 2015 @ 08:05
    keilo
    0

    How to write new API for the old Rest interface?

    I would like to change the following REST extension from older version to the new API model in version 7.

    [RestExtension("Helper")]
    public class Helper
    {
        [RestExtensionMethod(returnXml=false)]
        public static string MediaPathById(string id) {
            return new Media(int.Parse(id)).getProperty("umbracoFile").Value.ToString();
        } 
    }
    

    I have read the new API documentation and cant figure out the easiest approach to convert this, ideally if possible i would like to do a get with querystring.

    public class MediaPathGetter : UmbracoApiController
    {       
        [System.Web.Http.AcceptVerbs("GET")]
        [System.Web.Http.HttpGet]
        public string MediaPathById() {
    
         var test =0;
        var rid= System.Web.HttpContext.Current.Request.QueryString["id"];
         if (int.TryParse(rid, out test)) {
            return  ApplicationContext.Current.Services.MediaService.GetById(int.Parse(rid)).GetValue<string>("umbracoFile");
            }
        return "invalid request";
        } 
    

    If I try the above (hacky) code i get invalid keys for the mediaservice.getbyid method when i pass a valid media id.

    Would appreciate if someone can shed light.

Please Sign in or register to post replies

Write your reply to:

Draft