Interface to serve JSON and Rest RRS feed

  • Question

  • I have created an endpoint which will serve up JSON (see below). I'd like to reuse the interface to serve up XML Rest. Is there a recommended way of doing this?



        [WebGet(UriTemplate="/{username}",ResponseFormat = WebMessageFormat.Json)]

    Person auth(string username);



    Tuesday, December 6, 2011 10:06 PM


  • Generally the interface exposes two methods one to be used with XML and one for JSON. And the json and xml are to be used as an extension to the uri template.

    [WebGet(UriTemplate="/{username}.json",ResponseFormat = WebMessageFormat.Json)]
    Person AuthJSON(string username);


    [WebGet(UriTemplate="/{username}.xml",ResponseFormat = WebMessageFormat.Xml)]
    Person AuthXML(string username);

    Hope it helps.

    Can Bilgin
    Blog CompuSight
    • Edited by Can Bilgin Friday, December 9, 2011 2:59 PM Code block inserted
    • Marked as answer by Yi-Lun Luo Tuesday, December 13, 2011 9:56 AM
    Wednesday, December 7, 2011 9:01 AM