A new module idea: Orchard.Api

Topics: Core, Customizing Orchard, Writing modules
Jul 16, 2013 at 12:21 PM
I would like to officially propose the construction of a new module, whose responsibility would be to expose REST API support for Orchard content in a well-defined, configurable, and extensible manner.

This module could be called "Orchard.Api" (or something similar). I have used Orchard on several projects recently where an API was necessary for exposing functionality to mobile applications on iOS and Android, and I have had to write custom modules each time with the same code. In a lot of cases, I should have used Orchard features like Taxonomy fields but didn't because I had not standard way to expose Orchard Fields to an API.

This module would operate like the standard core modules for turning content parts into HTML--except it turns content and parts into JSON for use by mobile and other third party applications.

Content types would be turned into "JSON Shapes" based on their composition (parts, fields, and records) with each "part" able to extend what JSON is associated with it (or configured to be exposed by site settings).

An "Api Part" can be added to existing content types to enable them to be exposed. The settings for these parts determine which fields and properties are exposed in JSON--and under what conditions (for instance, an administrator can get a different set of fields and properties returned from a normal user). Permissions to data representations can be also based on role.

The power in this idea allows Orchard to be used to build a highly dynamic API-based content ecosystem like Salesforce.com.

Basically, the same sets of drivers, handlers, and filters would have to be represented or replicated for API hooks to allow the same type of customization capability that Orchard provides for delivering HTML content. A "ContentApiController" could return JSON serializable dynamic objects and accept JsonObjects as input. There could be an "ApiRoutable" part that allows for creating aliases that map to content type definitions, which, of course, define how JSON for POST and PUT operations should be interpreted based on content type and content part definitions.

This would also allow a truly generic Orchard Mobile SDK to be built for various platforms based on a single REST API as opposed to the custom API's that I have been building for each of my last 3 Orchard-based projects. Orchard can be made API-ready out of the box, which would make it an extremely powerful content-based application platform.

I would donate as much time as necessary to build such a module, but I would admittedly need help from people with more specific experience in each an every possible Orchard feature, since the goal is to expose everything that can be expressed as content as an API--even parts I am not used to using.

I would appreciate any feedback on my initial discussion of scope and features (adding support to existing types, limiting JSON based on roles and permissions, etc.).

I believe this work would make Orchard the most powerful CMS out there and rapidly increase its adoption, since distributing content and functionality to mobile applications is EXTREMELY important. Only Wordpress does an even decent job of this right now, and the features of Orchard 1.7 (e.g., media handling, workflow, etc.) provide the basis for providing an incredible mobile application and content management platform. Everyone needs this, I believe.
Coordinator
Jul 17, 2013 at 12:22 AM
I'd say go for it. This would be a great module. I'm not sure it would need to be in core at first, but that's fine.
Jul 17, 2013 at 12:50 AM
Awesome! It probably does not need to be a core module as you state. What are the thoughts about using GitHub as the repo instead of CodePlex? Is CodePlex still the standard?
Coordinator
Jul 17, 2013 at 4:32 AM
Github is perfectly fine, especially as we're going to switch the main repo to Git soon. Go for what you're most comfortable with.
Jul 17, 2013 at 10:59 AM
I have started a repo at Orchard.Api under the same BSD 2-Clause license used by Outercurve and the Orchard Project itself. The README will be updated with the text from the proposed feature set along with an initial check-in of module code later today. Shoot me a note here or via email if you are interested in working on it with me!
Jul 19, 2013 at 10:53 AM
@GQAdonis, do you want to discuss the project in this (codeplex) forum or should I ask question in the "issues" section of GitHub? Here is a link to my thoughts / question / code contribution:

https://github.com/CloudMetal/Orchard.Api/issues/1

I can move it back here if it makes the most sense.
Jul 19, 2013 at 11:25 AM
@jao28, I answered your question as a comment on that GitHub issues page! Thanks for responding! I figured at this point, we can do most of our "discussing" there until someone here requests otherwise or asks a direct question that the entire community might like to see.
Jul 25, 2013 at 2:33 PM
Edited Jul 25, 2013 at 2:35 PM
Interesting, I will get a look at your work. I will work on Android and WP8 next week, .... but clients not calling Orchard.

..... Recent mobiles are so powerful that we could run Orchard on them .... if there was IIS.....
Jul 25, 2013 at 2:37 PM
@CSADNT, That would be great! Once again, the code up there right now currently does only GET's with basic authentication support with no checks yet for authorized access to particular content types or administrative capability (permissions). These will be easily added later after I validate the rest of the "unknowns", which includes what makes sense to return as JSON, how much extensibility to support there, and validating the basic operation of POST/PUT semantics.
Jul 25, 2013 at 2:39 PM
@CSADNT: By the way, Orchard, I believe currently works on Mono and OWIN now, so it is not limited to IIS or the Windows platform. That really makes this work exciting.
Jul 25, 2013 at 2:44 PM
Later, I plan to follow up with mobile SDK's or iOS, Android, and WP8 in addition to PhoneGap plugins based on Backbone.js, Marionette.js, and Require.js that can pull mobile view templates from within Orchard via API's.

Orchard could be the most mobile-friendly CMS platform--and with Workflow, a premier general application server platform. Once all this is done, a source editor and build tools can be added based on recipe extensions that could allow Orchard to host its own development IDE/platform as well. The possibilities are endless and powerful.
Jul 25, 2013 at 2:48 PM
I add a very fast look (too fast certainly) on your project but I don't understand the usage of this Orchard REST API for mobiles, I must have missed something ?
What would be the main usage ?
Seems you are using Orchard as a remote database piloting content items ?