3

Suppose I have a resource like below:

namespace OpenRastaApp.Resources
{
    public class Foo
    {
        public string Bar { get; set; }
    }
}

a handler like:

namespace OpenRastaApp.Handlers
{
    public class FooHandler
    {
        public object GetAll()
        {
            ArrayList foos = new ArrayList();
            foos.Add(new Foo() { Bar = "Hello," });
            foos.Add(new Foo() { Bar = " world!" });
            List<Foo> result = new List<Foo>(foos.ToArray(typeof(Foo)) as Foo[]);
            return result;
        }
        public object Get(int id)
        {
            return new Foo() { Bar = "Baz" };
        }
    }
}

and a configuration as:

namespace OpenRastaApp
{
    public class Configuration : IConfigurationSource
    {
        public void Configure()
        {
            using (OpenRastaConfiguration.Manual)
            {
                ResourceSpace.Has.ResourcesOfType<Foo>()
                    .AtUri("/foos")
                    .And.AtUri("/foos/{id}")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
            }
        }
    }
}

/foos/1 renders as expected with:

{"Bar":"Baz"}

however, /foos does not render at all. The debug console shows the message "8-[2010-09-22 13:39:29Z] Information(0) No response codec was searched for. The response entity is null or a response codec is already set." I've verified that result is non-null before returning. I've also tried returning a Foo[], but that had the same error.

ktak
  • 596
  • 3
  • 9

2 Answers2

3

Figured it out. Had to modify my configuration as follows:

namespace OpenRastaApp
{
    public class Configuration : IConfigurationSource
    {
        public void Configure()
        {
            using (OpenRastaConfiguration.Manual)
            {
                ResourceSpace.Has.ResourcesOfType<List<Foo>>()
                    .AtUri("/foos")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
                ResourceSpace.Has.ResourcesOfType<Foo>()
                    .AtUri("/foos/{id}")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
            }
        }
    }
}
ktak
  • 596
  • 3
  • 9
  • 6
    Yes, we should really update the documentation. Lists of things and things are two different resources. We should at least have a warning / debug info to let people know – SerialSeb Sep 24 '10 at 01:08
  • Another option would be to use a list in either situation. That is the path I have started down, at least. – pc1oad1etter Oct 01 '10 at 16:36
  • Some kind of configuration analysis stage at startup seb? It could possibly output 'what do I have' information and the uri's for internal debugging along with the media types supported by each type? – Psiren Jun 17 '11 at 15:20
0

Just FYI, you could also have done the following:

ResourceSpace.Has.ResourcesOfType<Foo>()
    .AtUri("/foos/{id}")
    .HandledBy<FooHandler>()
    .AsJsonDataContract();
ResourceSpace.Has.ResourcesOfType<List<Foo>>()
    .WithoutUri
    .AsJsonDataContract();