Prev | Current Page 288 | Next

Brad Ediger

"Advanced Rails"

When rendering HTML, it uses a 3xx-series redirect
to satisfy web browsers. When rendering XML, it is assumed that the client will be cognizant
of all HTTP response codes, and it uses the appropriate response codes.
We see this in action in a typical scaffolded controller:
# POST /products
# POST /products.xml
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
flash[:notice] = 'Product was successfully created.'
format.html { redirect_to(@product) }
format.xml { render :xml => @product,
:status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors,
:status => :unprocessable_entity }
end
end
end
* Hence the name: Representational State Transfer.
192 | Chapter 7: REST, Resources, and Web Services
return, but cannot interpret. The concept of URIs as opaque values originates not
with Roy Fielding, but with Tim Berners-Lee:
The only thing you can use an identifier for is to refer to an object. When you are not
dereferencing, you should not look at the contents of the URI string to gain other
information.
This is a controversial idea, and the REST community is split over it. URIs have
evolved as a hybrid of opaque and transparent names. Particularly with humanfriendly
(???pretty???) URIs, people naturally expect to be able to interpret and modify
the URIs that they use.


Pages:
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300