<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bruno Pereira &#187; http</title>
	<atom:link href="http://brunopereira.org/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://brunopereira.org</link>
	<description>Open source, Java, web, python, client-side e outros hobbies :)</description>
	<lastBuildDate>Thu, 20 Oct 2011 00:47:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Uso de Hypermedia em protocolos REST</title>
		<link>http://brunopereira.org/2010/08/03/uso-de-hypermedia-em-protocolos-rest/</link>
		<comments>http://brunopereira.org/2010/08/03/uso-de-hypermedia-em-protocolos-rest/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 12:18:44 +0000</pubDate>
		<dc:creator>blpsilva</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[hypermedia]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://brunopereira.org/?p=370</guid>
		<description><![CDATA[Algumas vezes amigos já me questionaram sobre o uso de Hypermedia em protocolos REST. É sem dúvida um assunto que me agrada bastante, e acho que a discussão pode trazer boas idéias para quem implementar serviços REST interessantes.
Começando do começo: o que é Hypermedia?
Hypermedia é uma extensão lógica de Hypertext, na qual conseguimos combinar gráficos, [...]]]></description>
			<content:encoded><![CDATA[<p>Algumas vezes amigos já me questionaram sobre o uso de Hypermedia em protocolos REST. É sem dúvida um assunto que me agrada bastante, e acho que a discussão pode trazer boas idéias para quem implementar serviços REST interessantes.</p>
<h2>Começando do começo: o que é Hypermedia?</h2>
<p><a title="Hypermedia" href="http://en.wikipedia.org/wiki/Hypermedia" target="_blank">Hypermedia</a> é uma extensão lógica de <a title="Hypertext" href="http://en.wikipedia.org/wiki/Hypertext" target="_blank">Hypertext</a>, na qual conseguimos combinar gráficos, áudio, vídeo, texto plano e hyperlinks para criar um fluxo de navegação não-linear. (Definição retirada da Wikipedia).</p>
<h2>Motivação: REST sem Hypermedia</h2>
<p>No <a title="Artigo REST" href="http://brunopereira.org/webservicesrest-indice/" target="_blank">artigo de REST</a> que escrevi no começo de 2008 eu falei sobre diversos aspectos importantes em um protocolo de comunicação REST. Recomendo a leitura para quem ainda não tenha visto o artigo. Naquele artigo, cobri praticamente todos os detalhes aos quais devemos prestar atenção &#8211; a exceção ficou por conta de Hypermedia.</p>
<p>Para ilustrar uma resposta REST sem uso de Hypermedia, copio aqui uma listagem que usei no <a title="Artigo REST" href="http://brunopereira.org/artigos/" target="_blank">artigo de REST da Java Magazine</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">HTTP/1.1 200 OK
Date: nnn
Content-Type: text/xml; charset=utf-8
Content-Length: nnn
Last-Modified: Sat, 19 Feb 2008 13:40:03 GMT
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ofertasDoItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;oferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codOferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>23c32440-959a-4c33-b6ee-caff8e41422a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codOferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>111.22<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/valor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataModificacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2008-02-05<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataModificacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>b7d24e54-0c0d-4fa0-b4fe-d7cf60180ed7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;novo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/novo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vendido<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vendido<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ofertante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codUsuario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>505ab9d4-4b4b-4ce6-b128-b7408268126c<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codUsuario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ofertante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vencedora<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vencedora<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/oferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;oferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codOferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>41ffac11-5ba2-405b-acc8-8e3d0904b158<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codOferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>111.22<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/valor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataModificacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2008-02-14<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataModificacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>b7d24e54-0c0d-4fa0-b4fe-d7cf60180ed7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;novo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/novo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vendido<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vendido<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ofertante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codUsuario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>505ab9d4-4b4b-4ce6-b128-b7408268126c<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codUsuario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ofertante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vencedora<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vencedora<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/oferta<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ofertasDoItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Se você julga que isso parece um grafo de objetos serializado, você não está enganado, é exatamente isso.</p>
<h2>O que temos a ganhar com Hypermedia?</h2>
<p>Quando implementamos a API REST da autenticação/autorização/cadastro da Globo.com, o protocolo REST sem Hypermedia atendeu perfeitamente. A comunicação funcionou, permitiu integração de clientes de todas as plataformas, de forma desacoplada tecnologicamente. No que será que Hypermedia poderia ajudar?</p>
<p>O cerne do benefício de Hypermedia está no conhecimento prévio que os clientes devem ter sobre o seu protocolo. Repare no seguinte fragmento da resposta:</p>
<p>&lt;item&gt;<br />
&lt;codItem&gt;b7d24e54-0c0d-4fa0-b4fe-d7cf60180ed7&lt;/codItem&gt;<br />
&lt;novo&gt;false&lt;/novo&gt;<br />
&lt;vendido&gt;false&lt;/vendido&gt;<br />
&lt;/item&gt;</p>
<p>O que podemos dizer sobre ele? Ele traz informações &#8220;quase&#8221; completas sobre o item em questão. Todos os atributos estão presentes, porém não dizemos nada ao cliente sobre como interagir com este recurso, não é verdade? Um cliente que receba este XML conseguirá manipulá-lo <strong>SE JÁ SOUBER PREVIAMENTE COMO</strong>! O cliente já deve conhecer as URIs de cada recurso e saber quais manipulações ele pode fazer sobre os mesmos.</p>
<p>Como Hypermedia pode nos levar além? Com Hypermedia podemos dizer aos clientes como manipular os recursos, e com isso diminuir a inteligência embutida nos clientes.</p>
<h2>Exemplo de resposta usando Hypermedia</h2>
<p>Agora pegarei um trecho do meu artigo sobre AtomPub para exemplificar uma resposta com uso de Hypermedia:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:entry</span> <span style="color: #000066;">xmlns:atom</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/Atom&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:apps</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/apps/2006&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:gd</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/g/2005&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>https://www.google.com/a/feeds/example.com/user/2.0/SusanJones<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/atom:id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:updated<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1970-01-01T00:00:00.000Z<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/atom:updated<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:category</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/g/2005#kind&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">term</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/apps/2006#user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:title</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>SusanJones<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/atom:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;self&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/atom+xml&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;https://www.google.com/a/feeds/example.com/user/2.0/SusanJones&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;edit&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/atom+xml&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;https://www.google.com/a/feeds/example.com/user/2.0/SusanJones&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apps:login</span> <span style="color: #000066;">userName</span>=<span style="color: #ff0000;">&quot;SusanJones&quot;</span> <span style="color: #000066;">suspended</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">admin</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">changePasswordAtNextLogin</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">agreedToTerms</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apps:name</span> <span style="color: #000066;">familyName</span>=<span style="color: #ff0000;">&quot;Jones&quot;</span> <span style="color: #000066;">givenName</span>=<span style="color: #ff0000;">&quot;Susan&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gd:feedLink</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/apps/2006#user.nicknames&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;https://www.google.com/a/feeds/example.com/nickname/2.0?</span>
<span style="color: #009900;">username=Susy-1321&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gd:feedLink</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;http://schemas.google.com/apps/2006#user.emailLists&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;https://www.google.com/a/feeds/example.com/emailList/2.0?</span>
<span style="color: #009900;">recipient=us-sales@example.com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/atom:entry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Qual é a principal diferença aqui? Através do uso de <strong>links</strong> conseguimos indicar uma URI para manipulação do recurso, e através do atributo <strong>rel</strong>, indicamos QUAL é a manipulação. Algumas coisas ainda ficam implícitas. Por exemplo, se o link indica um <strong>rel=&#8221;edit&#8221;</strong>, a manipulação em questão provavelmente será feita com uma requisição HTTP PUT. Se o link tiver um <strong>rel=&#8221;show&#8221;</strong>, a manipulação deve ser uma leitura, feita com HTTP GET.</p>
<h2>Hypermedia x Acoplamento</h2>
<p>Neste ponto deve ter ficado claro que o uso de Hypermedia confere maior significado ao protocolo de comunicação. Em vez de trafegar dados crus, enviamos também metadados que permitem a construção de clientes mais genéricos dos nossos serviços.</p>
<p>Reduzindo o conhecimento que os clientes têm sobre o servidor, naturalmente o acoplamento diminui. O servidor precisa manter fixa apenas  a URI inicial da conversação, pois as posteriores serão informadas durante a comunicação.</p>
<p>O servidor pode também utilizar múltiplos tipos de conteúdo, de forma que alguns clientes consigam interagir de forma mais ampla. Um exemplo seria um IPod que sabe consumir podcasts, enquanto estes seriam ignorados por um browser comum.</p>
<h2>Precisamos de Hypermedia em um protocolo REST?</h2>
<p><strong>Resposta curta</strong>: na minha opinião não.</p>
<p><strong>Resposta longa</strong>: espero que minha resposta curta não tenha deixado a impressão de que não valorizo Hypermedia. Muito pelo contrário, acho que um protocolo que use Hypermedia será muito elegante e terá baixo acomplamento.</p>
<p>Entretanto, construir protocolos para clientes genéricos é bem mais difícil. Em alguns casos a decisão de diminuir o acoplamento aumenta na mesma proporção a complexidade do protocolo de comunicação envolvido.</p>
<p>É perfeitamente possível criar um excelente protocolo de comunicação sem Hypermedia. Você poderá ter clientes de múltiplas plataformas, conversando com seu servidor em múltiplos formatos de conteúdo.</p>
<p>Há um ponto de atenção no quanto seus clientes conhecem sobre seus formatos de URIs. Sem Hypermedia, mudanças de URIs podem quebrar seus clientes, o que traz um nível de acoplamento maior do que o existente com Hypermedia.</p>
<p><strong>Recomendação geral</strong>: o uso de Hypermedia é consistente com a arquitetura da web, utilizada há muitos anos com sucesso. Quando um protocolo de comunicação REST faz uso de Hypermedia, o acoplamento fica baixo e nos dá bastante liberdade para evolução. O ideal é tentar usar Hypermedia ao máximo desde o começo, mas sempre ponderando o nível de complexidade na construção dos clientes.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1066px; width: 1px; height: 1px; overflow: hidden;">
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:entry xmlns:atom=&#8221;http://www.w3.org/2005/Atom&#8221;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">xmlns:apps=&#8221;http://schemas.google.com/apps/2006&#8243;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">xmlns:gd=&#8221;http://schemas.google.com/g/2005&#8243;&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:id&gt;https://www.google.com/a/feeds/example.com/user/2.0/SusanJones&lt;/atom:id&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:updated&gt;1970-01-01T00:00:00.000Z&lt;/atom:updated&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:category scheme=&#8221;http://schemas.google.com/g/2005#kind&#8221;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">term=&#8221;http://schemas.google.com/apps/2006#user&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:title type=&#8221;text&#8221;&gt;SusanJones&lt;/atom:title&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:link rel=&#8221;self&#8221; type=&#8221;application/atom+xml&#8221; </span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">href=&#8221;https://www.google.com/a/feeds/example.com/user/2.0/SusanJones&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;atom:link rel=&#8221;edit&#8221; type=&#8221;application/atom+xml&#8221; </span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">href=&#8221;https://www.google.com/a/feeds/example.com/user/2.0/SusanJones&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;apps:login userName=&#8221;SusanJones&#8221; suspended=&#8221;false&#8221; admin=&#8221;false&#8221; changePasswordAtNextLogin=&#8221;false&#8221; agreedToTerms=&#8221;true&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;apps:name familyName=&#8221;Jones&#8221; givenName=&#8221;Susan&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;gd:feedLink rel=&#8221;http://schemas.google.com/apps/2006#user.nicknames&#8221; </span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">href=&#8221;https://www.google.com/a/feeds/example.com/nickname/2.0?</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;"> username=Susy-1321&#8243;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;gd:feedLink rel=&#8221;http://schemas.google.com/apps/2006#user.emailLists&#8221; </span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">href=&#8221;https://www.google.com/a/feeds/example.com/emailList/2.0?</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;"> recipient=us-sales@example.com&#8221;/&gt;</span></span></p>
<p style="margin-bottom: 0in;" lang="en-US"><span style="font-family: Courier New,monospace;"><span style="font-size: xx-small;">&lt;/atom:entry&gt;</span></span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://brunopereira.org/2010/08/03/uso-de-hypermedia-em-protocolos-rest/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>mod_rewrite</title>
		<link>http://brunopereira.org/2008/03/11/mod_rewrite/</link>
		<comments>http://brunopereira.org/2008/03/11/mod_rewrite/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 01:09:19 +0000</pubDate>
		<dc:creator>blpsilva</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[posts em português]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache software foundation]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://blpsilva.wordpress.com/?p=106</guid>
		<description><![CDATA[Hoje assisti a um Tech Talk bem interessante na Globo, sobre mod_rewrite. Além de funcionalidades interessantes deste módulo do Apache, as discussões na apresentação me trouxeram vários questionamentos de como incluir de forma mais ativa o Apache em uma arquitetura RESTFul.
Eu já utilizei bastante o Apache na remota época em que eu desenvolvia algumas coisas [...]]]></description>
			<content:encoded><![CDATA[<p>Hoje assisti a um Tech Talk bem interessante na Globo, sobre mod_rewrite. Além de funcionalidades interessantes deste módulo do Apache, as discussões na apresentação me trouxeram vários questionamentos de como incluir de forma mais ativa o Apache em uma arquitetura RESTFul.</p>
<p>Eu já utilizei bastante o Apache na remota época em que eu desenvolvia algumas coisas em Php. Na verdade não fazia nada de muito sofisticado, mas tinha boa familiaridade com os módulos, com a configuração, essas coisas. Depois que foquei mais no uso de servidores de aplicação Java, deixei o Apache em segundo plano. Praticamente só vinha usando o Apache para servir conteúdo estático, e claro, nele também ficam configurados os conectores para comunicação com os servidores de aplicação.</p>
<p>Como tenho trabalhado bastante com web services REST, venho tentando explorar ao máximo os recursos do HTTP para elaborar protocolos de comunicação concisos e intuitivos. Neste sentido, o Apache oferece recursos muito interessantes. Por exemplo, quando utilizamos URIs no formato /usuario/123456/item/25 para representar um determinado item de um determinado usuário, a resposta a esta requisição é cacheável pelo Apache. Entretanto, ao utilizar URIs neste formato você precisa definir uma forma de fazer o parsing da URI para pegar os parâmetros relevantes.</p>
<p>No meu artigo de REST da Java Magazine de Abril eu usei o StringTokenizer do JDK para fazer a quebra da URI e pegar os valores que me interessavam. A JSR-311 define uma forma bem interessante de fazer isso com annotations também. E hoje fui descobrir que o mod_rewrite também pode fazer facilmente a quebra de URIs neste formato em URIs com parâmetros em query string por exemplo.</p>
<p>Uma utilização inteligente do cache do servidor web e de módulos de proxy também pode tornar a arquitetura da aplicação bem eficiente e reduzir bastante a carga sobre os servidores de aplicação. Se eu posso utilizar diretamente o cache do Apache para várias URIs, não vale a pena deixar as requisições chegarem ao container de servlets, mesmo que ele responda também com dados em cache.</p>
<p>Vendo o poder e a facilidade de uso de alguns módulos do Apache, me sinto obrigado a ter total familiaridade com ele novamente. Aos poucos irei estudando e integrando os módulos do Apache à arquitetura das minhas aplicações REST, pois isto pode trazer um belo ganho de performance e escalabilidade. Afinal de contas, quem quer explorar a fundo os recursos do HTTP não pode abrir mão de explorar a fundo um servidor tão confiável e maduro como o Apache, não é mesmo?</p>
<p>OBS: uns anos atrás eu dizia pra mim mesmo que o dia que eu conhecesse pelo menos vagamente metade dos projetos na home da Apache Software Foundation eu já teria uma boa bagagem. Hoje em dia já conheço mais da metade do projetos da home, e admiro cada vez mais esta fundação. O mundo open source não chegaria aos pés do que é hoje sem a existência da ASF. Um belo exemplo de qualidade em software!</p>
]]></content:encoded>
			<wfw:commentRss>http://brunopereira.org/2008/03/11/mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando requisições HTTP através de proxies com o Commons HttpClient</title>
		<link>http://brunopereira.org/2008/03/04/criando-requisicoes-http-atraves-de-proxies-com-o-commons-httpclient/</link>
		<comments>http://brunopereira.org/2008/03/04/criando-requisicoes-http-atraves-de-proxies-com-o-commons-httpclient/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 00:37:59 +0000</pubDate>
		<dc:creator>blpsilva</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[posts em português]]></category>
		<category><![CDATA[commons-http-client]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[xstream]]></category>

		<guid isPermaLink="false">http://blpsilva.wordpress.com/?p=103</guid>
		<description><![CDATA[Hoje eu tive que criar algumas requisições HTTP através de um proxy, numa integração que estou implementando. Minha aplicação precisa enviar solicitações HTTP a um servidor remoto, passando por um proxy, e eu uso o Commons HttpClient para montar estas requisições.
Como achei a documentação disso bem fraquinha no site do projeto, resolvi postar aqui um [...]]]></description>
			<content:encoded><![CDATA[<p>Hoje eu tive que criar algumas requisições HTTP através de um proxy, numa integração que estou implementando. Minha aplicação precisa enviar solicitações HTTP a um servidor remoto, passando por um proxy, e eu uso o Commons HttpClient para montar estas requisições.</p>
<p>Como achei a documentação disso bem fraquinha no site do projeto, resolvi postar aqui um exemplo de código para facilitar quem possa precisar (e a mim mesmo no futuro). Este exemplo é um método de teste junit bem simples que monta uma requisição RESTful de cadastro de um novo usuário, especificando as configurações do proxy na API. Utilizei o XStream para fazer as manipulações XML. Segue o exemplo:<br />
<code><br />
public void testCriacao() throws HttpException, IOException{<br />
Usuario novoUsuario = new Usuario();<br />
novoUsuario.setLogin("fulano");<br />
novoUsuario.setSenha("123456");<br />
novoUsuario.setNome("Fulano");<br />
novoUsuario.setSobrenome("da Silva");<br />
novoUsuario.setStatusConta(1);<br />
novoUsuario.setTamanhoMailBox(6144);</code><br />
<code><br />
HttpClient client = new HttpClient();<br />
//servidor remoto que iremos acessar<br />
HostConfiguration hostConfiguration = new HostConfiguration();<br />
hostConfiguration.setHost("www.domain.com", 8080);<br />
// proxy pelo qual precisamos passar<br />
ProxyHost proxy = new ProxyHost("10.10.10.10", 9090);<br />
hostConfiguration.setProxyHost(proxy);<br />
client.setHostConfiguration(hostConfiguration);</code><br />
<code><br />
PostMethod method = new PostMethod("http://www.domain.com:8080/MailIntegration/usuario/");<br />
XStream xstream = new XStream();<br />
xstream.alias("usuario", Usuario.class);<br />
String usuarioXml = xstream.toXML(novoUsuario);<br />
StringRequestEntity requestEntity = new StringRequestEntity(usuarioXml, "text/xml", "UTF-8");<br />
method.setRequestEntity(requestEntity);<br />
int statusCode = client.executeMethod(method);<br />
assertEquals(201, statusCode);<br />
Usuario usuarioCadastrado = (Usuario)xstream.fromXML(method.getResponseBodyAsStream());<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://brunopereira.org/2008/03/04/criando-requisicoes-http-atraves-de-proxies-com-o-commons-httpclient/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RESTFox update</title>
		<link>http://brunopereira.org/2008/03/04/restfox-update/</link>
		<comments>http://brunopereira.org/2008/03/04/restfox-update/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 13:04:47 +0000</pubDate>
		<dc:creator>blpsilva</dc:creator>
				<category><![CDATA[posts em português]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://blpsilva.wordpress.com/?p=102</guid>
		<description><![CDATA[Após algumas conversas recentemente aqui na Globo, algumas pessoas se mostraram interessadas no RESTFox, pois facilitaria bastante os testes de nossas interfaces REST.
Após alguma pesquisa e alguns testes, descobri que o Firefox suporta de fato os métodos HTTP PUT e HTTP DELETE. Eles não podem ser usados em formulários, entretanto. Se você tentar utilizar algum [...]]]></description>
			<content:encoded><![CDATA[<p>Após algumas conversas recentemente aqui na Globo, algumas pessoas se mostraram interessadas no RESTFox, pois facilitaria bastante os testes de nossas interfaces REST.</p>
<p>Após alguma pesquisa e alguns testes, descobri que o Firefox suporta de fato os métodos HTTP PUT e HTTP DELETE. Eles não podem ser usados em formulários, entretanto. Se você tentar utilizar algum método diferente de GET e POST em um formulário, o browser converte a requisição para GET.</p>
<p>Já o XmlHttpRequest suporta estes métodos, e o RESTFox certamente faria uso disto, e não de um formulário. Sabendo que a idéia é válida, tentarei em breve começar o desenvolvimento do plugin, e quando já tver algo concreto coloco aqui.</p>
]]></content:encoded>
			<wfw:commentRss>http://brunopereira.org/2008/03/04/restfox-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diversidade de tecnologias</title>
		<link>http://brunopereira.org/2008/02/11/diversidade-de-tecnologias/</link>
		<comments>http://brunopereira.org/2008/02/11/diversidade-de-tecnologias/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 00:00:54 +0000</pubDate>
		<dc:creator>blpsilva</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[posts em português]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache abdera]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[atompub]]></category>
		<category><![CDATA[couchdb]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://blpsilva.wordpress.com/?p=83</guid>
		<description><![CDATA[Eu tenho postado com alguma freqüência sobre o que vem acontecendo no desenvolvimento das tecnologias dos web services Restful.
Este fim de semana o James Snell implementou um adapter do Apache Abdera para o CouchDB. Este adapter permite que se consiga facilmente implementar um armazenamento de dados no formato Atom com uso de uma instância do [...]]]></description>
			<content:encoded><![CDATA[<p>Eu tenho postado com alguma freqüência sobre o que vem acontecendo no desenvolvimento das tecnologias dos web services Restful.</p>
<p>Este fim de semana o <a href="http://www.snellspace.com/wp/?p=880" target="_blank">James Snell</a> implementou um adapter do <a href="http://incubator.apache.org/abdera/" target="_blank">Apache Abdera</a> para o <a href="http://en.wikipedia.org/wiki/CouchDB" target="_blank">CouchDB</a>. Este adapter permite que se consiga facilmente implementar um armazenamento de dados no formato Atom com uso de uma instância do CouchDB.</p>
<p>Como eu já mencionei <a href="http://brunopereira.org/2008/02/06/jersey-meets-abdera/" target="_blank">anteriormente</a>, o Abdera oferece uma API para manipulação de conteúdo no formato Atom e a realização de operações do Atom Publishing Protocol. Já o CouchDB é um banco de dados orientado a documentos que é escrito em <a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)" target="_blank">Erlang</a> e foi projetado para extrema escalabilidade e permite fácil instalação em servidores com múltiplos núcleos ou em clusters de máquinas.</p>
<p>Em vez de utilizar tabelas com colunas (como os bancos de dados relacionais), o CouchDB armazena os documentos em formato JSON e disponibiliza como interface uma API Restful, com clientes já implementados em várias linguagens, como Javascript, Java, PHP, Ruby e Python.</p>
<p>Acho que isto expressa muito bem o horizonte que vem se formando. Em vez de pilha de tecnologias e protocolos proprietários, temos diversas tecnologias e plataformas diferentes conseguindo se comunicar através de HTTP. Um projeto open source Java que manipula conteúdo Atom já disponibiliza com facilidade um mecanismo de integração com serviços REST que manipulam dados em formato JSON.</p>
<p>É impressão minha ou estamos de fato vendo rapidamente uma mudança radical de abordagem na vanguarda da tecnologia? A mesma IBM que antigamente dominava de forma absoluta todo o mercado de hardware e software com soluções proprietárias agora patrocina diversos projetos open source e mantém sua elite intelectual trabalhando nestes projetos.</p>
<p>Soluções open source estão liderando várias frentes de desenvolvimento e com isso rapidamente surgem integrações entre componentes feitos em diferentes linguagens e plataformas. O conhecimento não está mais guardado a 7 chaves, e sim discutido abertamente por uma comunidade que aceita qualquer um com capacidade para agregar idéias boas.</p>
<p>A criatividade e a iniciativa individual nunca tiveram tanto poder, e isto é fabuloso. Com isso, claro que a versatilidade e o conhecimento diversificado ficam muito valiosos.</p>
<p>Hum&#8230; maybe it&#8217;s time for me to fight my disgust for Javascript and start developing something nice including JSON <img src='http://brunopereira.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://brunopereira.org/2008/02/11/diversidade-de-tecnologias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

