devxlogo

RESTful Services with Rich Domain Logic Using RESTier

RESTful Services with Rich Domain Logic Using RESTier

Last week the OData team at Microsoft released a preview of the RESTier framework, built to allow developers to quickly bootstrap an OData service implementation. As a matter of fact, as is claimed in this MSDN blog post, it will actually take developers fewer than 100 lines of code in one controller to build a standardized OData V4 service with rich domain logic.

RESTier is based on Web API OData. It is inspired from the simplicity of building WCF data services with the flexibility of using Web API. It likely fills the much needed, and long ignored, void in the data services ecosystem that would allow developers to focus on their all-important business logic.

Note that the framework is in preview, so you can install it using the nuget console. It will not appear in the package explorer. To install RESTier in your SPA, Web API or MVC project, open the nuget console, and run the following command

PM> Install-Package Microsoft.Restier -Pre

You can now start creating the Domain files based on the associated data providers. Note that in its current form, RESTier only supports EF 6 as the data provider. So if your project has an Order repository, with the database context as OrderContext, then you can create an OrderDomain class with the following code:

using Microsoft.Restier.EntityFramework;public class OrderDomain : DbDomain{    public OrderContext Context     {         get { return DbContext; }     }}

For the controller, you can add the OrderController.cs class under the Controllers folder that inherits ODataDomainController class part of the RESTier Web API namespace.

public class OrderController : ODataDomainController{    private OrderContext DbContext    {        get { return Domain.Context;}    }}

To complete the bootstrapping process, you also need to register the OData endpoint in your WebApiConfig.cs file (for a Web API project).

config.MapODataDomainRoute(           "OrderApi", "api/Order",            new ODataDomainBatchHandler(server)); 

All set. Run the application and browse http://locahost/api/Order and then you will see the entity set. You can now run the all familiar OData commands for CRUD operations.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist