Very first draft of Restfulie server

13 views
Skip to first unread message

Mauricio Aniche

unread,
May 12, 2010, 12:31:19 AM5/12/10
to restfuli...@googlegroups.com
Hi guys,

I have a very first draft of restfulie server for asp.net mvc 2. I want some opinions:

The model needs to implement an IBehaveAsResource interface which has a method to define its transitions.

public class Order : IBehaveAsResource
    {
        public DateTime Date { get; set; }
        public double Amount { get; set; }

        public void SetTransitions(Transitions transitions)
        {
            transitions.Named("pay").Uses<OrdersController>().Index();
        }
    }

The controller needs to have the attribute [ActAsRestfulie]. In the action, it should return a RestfulieResult like Success (which returns http 200 and the resource). You can also send a different result if you want (for example, return new BadRequest()).

[ActAsRestfulie]
public class OrdersController : Controller
{
    public virtual ActionResult Index()
    {
        var order = new Order {Amount = 333.44, Date = DateTime.Now};
        return new Success(order);
    }
}

The content negotiation is working. It is still pretty simple as it only accepts "application/xml". However, if a non-supported media type is provided, restfulie sends a Not Acceptable (406) automatically. 

I tried to keep the asp.net mvc development mindset. I guess it is pretty easy to use. 

I am about to start the next ticket on lighthouse that is atom support. Any suggestions before that?

Regards,
Mauricio

Mauricio Aniche

unread,
May 12, 2010, 12:32:46 AM5/12/10
to restfuli...@googlegroups.com
Oh, the code is in my github : http://github.com/mauricioaniche/restfulie.net

I still need to make a nant build file. But you can compile and run it in visual studio.

Guilherme Silveira

unread,
May 12, 2010, 10:34:38 AM5/12/10
to restfuli...@googlegroups.com
Hello mauricio,

I have made a mistake on the first beta release from restfulie, i used to call trasnitions what were, in fact, relations. Transitions are a subset of all possible rerlations. So we have changed..

Therefore in the ibehaveresource i would call getrelations instead of gettransitions. And also pass a relationsvfactory. Its just a rename refactor, actually.

I am offline so i did not look the github project, are there unit tests alreAdy?

And lets move on to atom.

Regards

Guilherme Silveira

Mauricio Aniche

unread,
May 12, 2010, 10:56:52 AM5/12/10
to restfuli...@googlegroups.com
Hi Guilherme,

Great, I am gonna rename them!

Yes, there are some unit tests in which I used to help me design (haha, I'm a TDDer! :P). But this is another point I want to discuss, so I will create another thread for it.

If you guys know any .NET OSS library that handles atom, it would be great. I guess it is much easier than do all the dirty work. I will look for it.

Regards,
Mauricio

Brad Jones

unread,
May 12, 2010, 12:39:34 PM5/12/10
to restfuli...@googlegroups.com

Mauricio,

 

You might want to take a look at Atomsite: http://code.google.com/p/atomsite/

 

Furthermore, there are some excellent patterns server-side implemented in OpenRasta that you might want to review : www.openrasta.com

 

Cheers,

 

Brad

 

 

 

Reply all
Reply to author
Forward
0 new messages