How can i implement web API in Orchard custom module

Topics: Customizing Orchard
Aug 17, 2015 at 3:48 AM
I have one web API URL and it's returns some XML values, how can I retrieve that XML values into my custom module.

API URL like:
Aug 17, 2015 at 7:10 AM
Edited Aug 17, 2015 at 7:12 AM
You can just create a module and throw in an API controller in there with those methods. Then you only need to define the Routes to get it working with the url you want.
The default route that is made by Orchard to your api is as following:


To cleanly get the url in your code, you can use the following piece:

var actionUrl = Url.Action("Method", "Controller", new {
    httproute = true,
    area = "MyModuleName"
Aug 17, 2015 at 12:44 PM
Edited Aug 17, 2015 at 12:48 PM
Can you please show one sample code?
Aug 17, 2015 at 2:58 PM
Hi Nitheesh - I've just been playing about with this :)

Here's a snippet based on what I did - this would bring data from a hypothetical materials part, using a materials viewmodel, you'd get JSON back
        public IEnumerable<MaterialViewModel> Get()
            List<MaterialViewModel> m = new List<MaterialViewModel>();
            var x = _materialRepository.Table;
            foreach (var item in x)
                m.Add(new MaterialViewModel
                    Title = item.Title,
                    MaterialID = item.MaterialID,
                    Description = item.Description

            return m.AsEnumerable();
hope that helps
Aug 17, 2015 at 3:44 PM
Thank you eRuth....