What is the best method for creating an API using MVC3 - asp.net-mvc-3

I am using mvc3 and I want to create an API with the site.
MVC makes it really easy to return json from the controller which I know how to do.
I want to use a subdomain for the api something like http://api.mydomain.com
I have a few questions
Do I create an area for api or just place the controller and model in the root?
How can I point to the subdomain so the url is api.mydomain.com not mydomain.com/api
What is the best way to version the api? do I just create a new controller for each version e.g. V1Controller,V2Contoller etc etc
Any suggestions would be really helpful.
Thanks for your help

I have recently used ServiceStack, I really like working with it, you should take a look
http://www.servicestack.net/

Related

How to best apply an MVC architecture in dojo mobile (custom controllers)?

I'm pretty new to Dojo and I'm wondering about some best practises for building a MVC application. I know there are modules like dojox/app, but it seems like these are made for more complex applications.
It seems like the best way to go is to make custom page-level controller objects with will handle all the page logic, but I'm not quite sure how to fit this piece in the puzzle. What is the proper way to switch between views and passing through parameters through them following a MVC archtiecture.
I have an overview page with list items, each with their own ID. I want to navigate to another page passing through the corresponding item ID so I can retrieve the details for this item externally. What would be the proper way of doing this?
I could call a method on the corresponding controller (Page1 Controller or Page2 Details controller) directly using a button and passing the listID parameter directly?
Another way of doing this could be by working with transition states and addling listeners in the page controller to forward to the correct page. Although I'm not quite sure how to pass parameters in this scenario..
... any better solutions?
Can anybody shed some light on this? It doesn't seem like there is much documentation/examples on this with the latest versions of dojo (1.9).
Thanks!
I will recommend dojox/app since you are already using dojo mobile.
It's very simple to get started and can be use for simple apps or very complex apps
Take a look at this resources:
https://github.com/csantanapr/dapp-examples/tree/master/dapp-request
https://github.com/csantanapr/dapp-boilerplate
http://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsList/

RESTful API with CMS Made Simple

I have a client with a content-heavy site built in CMS Made Simple. The redesign requires a mostly AJAX interface, and I think a frontend framework like Backbone or Angular would be the way to go.
I want to avoid moving off CMS Made Simple, though (client is used to that interface, it will be annoying to migrate all the data).
I think if I could find or create a RESTful api for CMS Made Simple, I'd solve my problem. But after searching around online, I only found CGSocialApp module, which seems to provide a limited API for things like user management. I've also looked into other AJAX solutions for CMS Made Simple, and there don't seem to be good modules for it.
If there is no ready-made solution for me, how complex would building a RESTful API module be? I haven't built a RESTFUL api in a PHP framework before.
Thanks for any guidance!
So, there is no easy answer for this question, as the CMSMS doesn't have a build-in RESTful API.
I would go for one of the two solutions:
1. Output the content as hand made json.
In CMSMS, you really have a lot of control on the templates. You could change the default templates to output json content instead of HTML content. The only issue is that the CMSMS will still send an http content-type header, that you can try to ignore in the JS part.
To access the menu, just remove it from the main template and create an empty page who output the {menu}with a custom template that also build json content.
That's the quick and dirty solution, but it should be very accessible in terms of doing it.
2. Create a dedicated module.
As far as I know, there are no modules that expose the CMSMS in RESTFul format, but a module is really very easy to build. Well, you can try to build it yourself, with the help of the community. It don't really solve the current problem, but it's a hint.
I hope it shed some light on the problem.

Ajax implementation with Django

I am presently working on a Django project that requires the implementation of Ajax.
e.g adding model objects to the database, getting and updating model instances from the database etc without refreshing the page at all.
I have searched everywhere but am yet to come across any relevant material.
I would implore the gurus in the house to point me in the direction of materials you know could seriously be of help. Thanks
Django Ajax forms
Dajax project
Ajax and Django views
What you ask looks like implementing a RESTful API (create, update and get objects...)
You should have a look at Tastypie or Piston
For a comparison of those two look at this question

Database interaction with codeigniter and backbone.js

I am trying to learn backbone.js to make a web application.This is my first time with a javascript framework and I am fairly confused with some of the stuff.
I have been developing in codeigniter for a while so I do have a understanding of the MVC architecture.
My question is how do I get the data from the backbone.js front end to my codeigniter controller and save it in the database. for example to implement a simple login/register functionality with CI and backbone, how should I proceed. If anyone can guide me step step then that would be great or point me to the right resource. Thank you.
PS: I know that I have to implement a REST api with my codeigniter but I don't know how? so if someone can provide a basic controller example it'd be really helpful.
Here's a tutorial to use the API mentioned in the above reply (by the author of the library himself)
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

ASP.Net MVC3 webapplication directory structure

I am moving our current ASP.net website to a MVC3 project and am very new to MVC. Currently we have a 2 level authorization for a superadmin and a admin. Both these levels of authorization get directed to a menu where there are some common and some different pages which they each access. I was wondering how I could structure it such that there will be minimum duplication of controller logic with URLs like -
myURL/SuperAdmin
myURL/SuperAdmin/Users
myURL/SuperAdmin/Users/UserId
Similarly for Admin.
For the above kind of URL I may have to duplicate the controller code (for the Users view) in the SuperAdmin as well as the Admin controllers. As both these access the Users View. I would like to avoid this, but have the same URL. We are making use of the existing business layer entity framework (stored procedures) and not using any LinqToSql. Can I use named routing for this? If so, how? I hope I am making myself clear.
Can someone please help? Any ideas and suggestions will be greatly appreciated.
Thanks,
sdd
I'm not entirely clear on this. If you think you will have code duplication then remove that code into common classes that multiple controllers will access. Sure you can have multiple routes point you to the same controller/action methods (if thats what you meant) but I recommend you don't have multiple URI's (excluding varying parameters) that go into the same controller method. It makes your app a bit hard to follow.

Resources