Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Custom Sample in WebAPI Help Page

$
0
0

I implemented one custom media formatter to provide pdf file. I created custom formatter with 'UriPathExtensionMapping' as media type mapping. All working fine and i can get the pdf file. Currently I allowed all types to write as pdf testing and the code below;

        public override bool CanWriteType(Type type)
        {
            return true;
        }

Now i need to set custom sample to webapi help page. For this i used the following code in Help page configuration.

            config.SetSampleForMediaType(
                    new TextSample("Not Applicable. Return PDF file."),
                    new MediaTypeHeaderValue("application/pdf"));
        }

This also working fine.  But displayed in all of my apis. Now i need to allow only particular api to support this pdf. The following is my ,model;

    public class Person
    {
        public string Name { get; set; }

        public string Place { get; set; }
    }


Then i changed the write support this type only.

        public override bool CanWriteType(Type type)
        {
            return (type == typeof(Person));
        }

All my code working and getting pdf for that api also. But now none of my api (even if the Person api with ext) showing this pdf support and custom sample. Why? any other settings need to add?


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>