The Counterintuitive Web
Recorded at:
What's wrong with having to peer inside the body?
by
Bediako George
if (body has this)
{
//this stuff
}
else if (body has that)
{
//that stuff
}
else if (body has the other)
{
//the other stuff
}
else if (etc ...
Instead think of separating each of those state checks in separate controllers each referenced by a single URI. For every "if else" you may need another resource. In this way the URI act as a type of router, automatically routing the resource you are changing to the right controller.
A direct side effect of this is easier to understand code, greater decoupling, and in my opinion less bugs created by trying to wrap your minds around all those if statements.
This video is a very good treatment on resource oriented design and Rest.
Impressive.
Did he just make stuff up.
by
William Cherry
Re: What's wrong with having to peer inside the body?
by
Nat Pryce
In that case, the handler looks up an unmarshaller keyed by the content type of the body, uses the unmarshaller to turn the bitstream of the body into a running object, tells the object to act. and the object does whatever it does.
E.g.
Unmarshaller unmarshaller = unmarshallers.lookUp(request.contentType);
PostAction action = unmarshaller.unmarshall(request.body);
action.performUpon(theActualResource);
Re: Did he just make stuff up.
by
John Schlesinger
... The ..\Order\123 GET should get a resource named 123, ..\Order PUT, creates a resource, ..\Order\123 POST should modify the order. Period. ...




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think