Using asp.net mvc for a REST-based endpoint

I am considering using ASP.Net MVC as a platform for a REST-based service. I know that WCF supports support for REST services; however, I am looking at the return of several data types depending on the request.

I would like the client to request the type of content. Therefore, if they send text / html, for example, I would turn my model into Html, if they request text / xml, it will return xml. We could also do JSON.

Anyone see any problems with this?

Not using WCF can increase the complexity of the client when calling the service, because they will not be able to automatically generate proxies; however, in my case, the clients will be either a browser requesting html or java client libraries that process xml.

Since we did not use WCF, we need to provide service; however, I think we can do this using forms-based authentication.

The advantage of this is that no matter what type of data the client requests, everyone goes through the same controllers / models, etc.

+5
source share
3 answers

After reading the Haack post about using extensions to indicate the type of content, I think you'd better turn off header reception. It seems more Rest'ish to me, although it was a little harder to launch the browser and check your URL.

ModelBinder HttpContext : http://jberke.blogspot.com/2009/03/aspnet-mvc-model-binder.html.

, Troy, Xml . xml- . . , . , -.

+2

Haack, , , .

, Entity Framework ( Linq SQL - ), JsonResult , ( , ). -, .

- X-Requested-With HTTP, , XHR. Content-Type: text/xml XML.

Firefox REST, XHR. Tamper Data /. WFetch - HTTP, .

JSON/POX . [JsonPox], JSON XML .

+3

, :

http://haacked.com/archive/2009/01/06/handling-formats-based-on-url-extension.aspx

(.html,.json,.xml) , Accept-Encoding ( ).

.. , "" , , . HTML- , . XML/JSON, , , viewdata, , .

+2

All Articles