Last active
March 19, 2017 16:33
-
-
Save marco-mendes/a2f083750d7d508083649cf4a0dc06cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RoutePrefix("api/books")] | |
public class ControladorLivros : ApiController | |
{ | |
[Route("api/livros")] | |
public IEnumerable<Livro> ObterLivros() { ... } | |
[Route("api/livros/{id:int}")] | |
public Livro ObterLivro(int id) { ... } | |
[Route("api/livros")] | |
[HttpPost] | |
public HttpResponseMessage CriaLivro(Livro livro) { ... } | |
} | |
class Livro { ... } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /index.html HTTP/1.1 | |
Host: www.exemplo.com | |
HTTP/1.1 200 OK | |
Date: Mon, 23 May 2016 22:38:34 GMT | |
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) | |
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT | |
Etag: "3f80f-1b6-3e1cb03b" | |
Accept-Ranges: bytesContent-Length: 438 | |
Connection: close | |
Content-Type: text/html; charset=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT /produto/1234 HTTP/1.1 | |
<produto> | |
<titulo>Cerveja Backer Tommy Gun Double IPA</titulo> | |
<preco dinheiro="brl">9.50</preco> | |
</produto> | |
POST /produtos HTTP/1.1 | |
<produto> | |
<titulo>Cerveja KSB Living The Dream Double IPA</titulo> | |
<preco dinheiro="brl">13.50</preco> | |
</produto> | |
HTTP 1.1 201 Created | |
Location: /produtos/1789 | |
POST /produtos/minha-nova-cerveja HTTP/1.1 | |
<produto> | |
<titulo>Cerveja Dogma Azzaca Lover</titulo> | |
<preco dinheiro="brl">8.50</preco> | |
</produto> | |
HTTP 1.1 201 Created | |
Location: /produtos/minha-nova-cerveja |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
public class AloMundoMicrosservico { | |
@RequestMapping("/alo") | |
public void alo() { | |
// Metodo controlador invocado a partir do endereco http://localhost:8080/alo | |
// Metodo pode invocar as regras de negócio daqui e manipular o seu próprio banco de dados. | |
} | |
} | |
@SpringBootApplication | |
public class Microsservico { | |
public static void main(String[] args) { | |
SpringApplication.run(Microsservico.class, args); | |
} | |
} | |
// Na linha de comando o seguinte comando é executado. depois que o JAR (executavel Java) foi gerado. | |
java -jar build/libs/Microsservico.jar | |
// O JAR contem os codigos binários das classes Microsserviço (ponto de entrada) e AloMundoMicrosservico (que expoe recurso REST) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment