This project is read-only.

Hosting Business Classes as a REST Service

In the new Preview CrowFX release we added a new breaking feature called, CrowHost.

With CrowHost you can instantly create an JSON supported REST API for your BusinessClass. CrowHost uses the Asp.Net Web API base as a host service. And also can be host from any client by the help of Self Host feature of Web API.

See the example below;

            using (ICrowHttpHost host = CrowHost.ConfigureHost().Host<IDataBusiness>().Start())
            {
                Console.WriteLine("Press enter to stop application.");
                Console.Read();
            }

You can now call your Business Class by requesting the Url below;

http://localhost/IDataBusiness/GetDataById?id=2

Primitive parameter types can be called by the querystring. However more complex types must be called by POST method. Suppose you have a business interface implementation like this one;

   public interface IFakeUserBusiness
        {
            int MultiplyFiveBy(int number);
            Foo GetFooById(int id);
            Foo GetFooByFooAndId(int id, Foo foo);
        }

And I assume you have made an implementation of this interface and bind these two type at the Module.Install method. (see the Bootstrappers and Modules for more information.) Now if you start your host by calling the CrowHost.ConfigureHost().Host<IFakeUserBusiness>().Start()) method, you can expose this business interface with these queries;
  1. http://localhost/IFakeUserBusiness/MultiplyFiveBy?number=?? (GET)
  2. http://localhost/IFakeUserBusiness/GetFooById?id=?? (GET)
  3. http://localhost/IFakeUserBusiness/GetFooByFooAndId?id=?? (POST)

There is no problem with the first two requests, however in the third one you have to add your Foo object on the POST Data by serializing like the code below;

{ 
   foo : {
         Text : "",
         Id : 4
   }

You might also want to add id parameter to the Post Data;


{ 
   foo : {
         Text : "",
         Id : 4
   },
   id : 4

As you see the handler always check for the both query string parameters and the Post data parameters that matches the method argument's name. But querystring parameters always overrides the Post data parameters.

Adding Documentation to the API

(this topic is added only for placeholder. We're still implementing this feature.)

Last edited Aug 17, 2012 at 10:13 PM by msusur, version 1

Comments

No comments yet.