Feedback on ASP.NET Web API

Create an HTML Formatter

As suggested in the Add a HTML MediaTypeFormater to the Web API response, I would like to see a pure HTML Formatter. This would not use views or razor, rather it would generate a simple HTML page based on the model passed in. It would work like the XML and JSON serializers, producing a standard HTML format... objects would start with a <dl> tag with a class attribute set to the class name. It would contain a <dt> <dd> pair for each property. If a property was a list, the <dd> would contain a <ul> where each <li> would contain a new <dl>.

I have written one previously that was based on JSON.Net... basically JSON.Net is used but a new HtmlWriter derived from JsonWriter is passed to the JsonSerializer.Serialize method... the advantage being JSON.Net does the heavy lifting of reflecting over the object and the new serializer obeys all the attributes that the model has on it already to control the JSON format.

Once registered, this formatter allows somebody to navigate around the API (read only) in a standard browser... especially if a convention / configuration is used to indicate which property values should be wrapped in an <a> element (e.g. all properties called uri).

14 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    PiersPiers shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • PiersPiers commented  ·   ·  Flag as inappropriate

        If we could top and tail the generated HTML with some configured HTML (so a <head> could be injected possibly with a link to a CSS file) or provide delegates that could dynamically add the top and tail, the API could even look "pretty" and approachable. We find an API that is browsable is easier to get to grips with and to test.

      Feedback and Knowledge Base