How, in general, can web framework support REST style? - language-agnostic

I would like to know, what are the ways a web framework may be suitable for designing a RESTful app, in general.
One goal is for example to provide http request routing, so they are automatically sent to appropriate controllers. From architectural point of view, web framework based on MVC pattern are more suitable for REST.
What other features of web frameworks are helpful by building apps satisfying the REST constraints?
Is there any reason why you consider certain languages(python/java) or web frameworks(django/turbogears/jersey/restlets/...) as the most applicable ones?

I think the best way for a web framework to support a RESTful style is to automatically map the different HTTP verbs (GET, POST, PUT, DELETE, etc.) to corresponding methods on its controllers/request handlers. Most modern Python web frameworks do this out of the box, with the notable exception of Django (unless I missed a dramatic change).

a) You need very flexible routing.
b) You need to be able to easily generate links that correlate to resource controllers using templates and parameters.
c) The server should help you to parse all the http headers. e.g. Authorization headers, Accept headers, language headers, cookies, etags.
d) It should support serializing and deserializing all the commonly used mime types.
e) It should help parsing parameters from incoming URLs
f) It should help resolving relative urls based on the request url and any available BaseURL.

There are few ways that a web framework can NOT support REST. Its basically written with the HTTP model in mind; so just about any web framework works. The automatic routing you mention is a common expectation, but not strictly required for REST.

I would stress the ability to directly support definition of resources. In Ruby on RAils you can define a resource through scaffolding and you get a model with controller with restful verbs implemented also with views and support for different formats and readily avalaible views and routing with ids.
Aside from that having access to HTTP and supporting principles of HTTP is what you need.
I am not experienced enough to know about support in frameworks, but it would be also nice to have support for the caching and other request options.

On the “specific software recommendation” front, I've had people recommend Apache CXF as a framework for building RESTful services with Java. It appears to be even able to simultaneously support SOAP (which happens to be very useful for helping some of our customer base adopt the software). I'm still in the experimenting-with-it stage though, so you may be able to do better.

Related

The Simple way for the Polymer Backend

It is not clear to me how to use Polymer for implementing the backend. What is the natural way to process the backend for Polymer? Please show brief sample code to be clear.
As mentioned, Polymer.js is a front end library, specially to provide access to Web Components APIs as they are called.
There is no particular way to make a web request, in fact, though there are elements (iron-ajax) that can help, really you are on your own.
Given that polymer is mostly here to provide early access to Web Component development (and use), personally I decided to use fetch, the coming (low level, at least) standard for AJAX in Javascript.
Here is a link to a polyfill for the fetch API.
https://github.com/github/fetch
IOW: you are on your own making an ajax request, use the Fetch API or some other library of your choosing.
Then you build a RESTful back end and it doesn't matter what sort, though it's common to use Node.js with Express.

Node.js + Framework for RESTFul API

I'm new to Node so maybe someone can help me in this decision, I want to create RESTFul API that are accessible from a web site and from mobile application returning JSON response.
I have decided to use the same API for the website and for the mobile applications for a maintain purpose, I went from a disastrous platform where the two logic part were separated. Also I want to use only RESTFul API without session for a scalability purpose, using an OAuth2 authentication and maybe Memcache to serve same JSON response thanks to the hash algorithm used.
I begin with Node+Express.js+MongoDB for the backend, but I have noticed that Express come with a lot of package to control and use cookie, template engine and so on...
So my question is: Express.js is the right package for my purpose? Or is better to not use this Framework? In your opinion what is the best way to achieve speed of access and speed of serving without any type of session and without any type of cookie?
I developed some RESTful APIs with Express. The good thing about Express is that you don`t need to use all the additional stuff like session handling and template engines.
In addition there are some really good modules that enables you to set up an API very fast.
For example if you are using mongoose have a look at Baucis.
If you still feel uncomfortable with Express, there are many other node.js frameworks for building RESTful APIs. Maybe give Restify a try?
Restify is somehow like a specialized version of Express, so it is really easy to migrate existing code.
You can go for Strongloop as well. Strongloop is a wrapper on express, but it has many features which makes it very powerful for building RESTful APIs.Please check this link https://strongloop.com/

Partial response in Spring MVC

Our RESTful application need to support 'partial responses' to limit bandwith.
By this I mean that the REST client tells the URI service which fields of the resource it is interested in.
For instance: api/v1/users/123/fields=firstName,lastName,birthDate
We're using Jackson parser to convert our DTO's to a JSON structure.
The problem is that we cannot tell at runtime to 'skip' some properties.
We should need to create a class at runtime with a variable amount of properties to accomplish this. But I don't think this is possible in Java, it is a static language after all.
While searching the internet we found some semi-solutions by just returning a java.util.Map containing the requested properties or filtering out properties by the Jackson parser.
Especially the latter seems a 'hacking solution' to me. It seems that Spring MVC doesn't provide an out-of-the-box solution for this issue...
Is there any alternative in the Java world we can use to solve this issue?
How about Yoga
Yoga extends JAX-RS and SpringMVC RESTful servers to provide GData and LinkedIn style field selectors.
Choose which fields you want to see at call-time
Navigate entity relationships in a single call for complex views
Much faster speeds in high-latency (e.g. mobile) apps
Streamline client development
Browsable APIs

ASP.NET web api: documenting/specifying a service

I've been looking at asp.net Web Api, and I like the simplicity of implementing a practical web service.
However, how can I document/specify the interface of a service implemented like that? For example, is there any spec I can pass on or generate to a Java guy with no .NET background that will let him easily call and consume the service? What can I give to the javascript guy?
Ideally, I'd like the benefits of SOAP/XSD or something like it (easy to deserialize with nicely typed objects) for the java guy, while retaining a service that's callable from a web browser too (i.e. supports non-crufy JSON).
Update
It's worth noting that since I originally posted this question, I discovered ServiceStack which deals with this more naturally; supporting JSON, SOAP, and WSDL out of the box for the same service, as the client chooses. If you really want SOAP+JSON, it may be a better framework than ASP.NET Web Api.
Update March 2016
It has been a while since this was answered and the tooling for documenting any Rest API has come along a lot. We are currently evaluating Swagger 2.0 now spawning out to the the Open Api Initiative, RAML and API Blueprint.
For WebAPI projects there is a tool Swashbuckle that auto creates Swagger (Open API) format documentation.
Format for documenting a REST service:
There are some attempts at structuring and standardising the description of REST services:
Web Application Desciption Language (WADL)
Web Service Description Language 2.0 (WSDL 2.0)
I think it is fair to say neither of the two approaches above have very wide adoption, but WADL does look like a nice concise format - a quick XSLT over the top and it could be a nice human readable format. There lots of examples of WADL for some famous API's at the apigee github site here.
When trying to find a documentation format that is appropriate I tend to look for "inspiration" from others.... Apigee do a lot of research in this area and have this as documentation for one of their API's here or take a look at Facebook's social graph api here.
The examples are largely in line with the advise here
How to auto document:
Using .NET: There is a good example of auto generating a WebApi "help" page here. A logical extension of this example may be to get it outing a WADL formated version as well...
Using Java: Jersey is a tool used in the Java community to generate WADL automatically.
What to share with the other developers:
Your Javascript guy will most likely want a manual like the Facebook and apigee one; giving the dev examples of the resources, urls, response codes etc. The most important thing here will be supporting JSON as the primary content type this will be the easiest for him/her to consume and work with by far.
Your Java guy would also want the manual, but also in theory they could be given example XSD for any XML representations of the resources you send/consume (assuming they make the request as "Content-Type: appplication/xml"). This may help them build proxy classes etc. JSON to Java and .NET converters are available online and given the example resources in your manual they should simply be able to use one of these types of services to quickly create proxies. Generate Java class from JSON?.
If you absolutely must have auto discovery, auto proxy generation etc then you may need to offer a choice of both REST and SOAP (with WSDL) endpoints - relevant question here: ReST Proxy Object Generator.
You can use IApiExplorer interface and ApiExplorer class in order to create a help page for your Web Api service. This help page will describe the REST methods exposed by your service so any developer who understands how REST works will be able to use it (regardless the language). Please read below links for details and samples:
ASP.NET Web API: Introducing IApiExplorer/ApiExplorer
ASP.NET Web API: Generating a Web API help page using ApiExplorer
Documenting your ASP.Net Web API’s

How can i build a WCF+MySQL Server which can communicate with differents clients(differents OS)?

I want to build a WCF Server with MySQL Database which can communicate with differents Clients on differents OS. Is that Possible?
if Yes, how should i go? any tutorials which can help me?
Cheers
Is that Possible?
Yes, interoperability was one of the main concerns of the WCF designers.
how should i go?
There are so many options you need to consider, for example security, reliability...
But mainly basicHttpBinding is probably the most interoperable SOAP-based binding. Just google for samples of basicHttpBinding.
On another account, the most interoperable WCF approach is WCF REST which can allow use of JSON that any client can understand, even the browser. However, implementation of WCF REST has quite a few design problems (outside scope of this question) and I would suggest using ASP NET MVC to implement passing JSON objects over HTTP. For security, you can use HTTPS.