Skip to content

Instantly share code, notes, and snippets.

View marco-mendes's full-sized avatar

Marco Mendes marco-mendes

View GitHub Profile
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
public static void main(String[] args) throws UnknownHostException {
SpringApplication app = new SpringApplication(AngularspringbootmicrosservicoApp.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
log.info("\n----------------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
router.get('/', async (req, res) => {
const users = await User.find();
return res.send({ users });
});
router.post('/login', async (req, res, next) => {
const { name, password } = req.body;
try {
@Endpoint
public class CountryEndpoint {
private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
private CountryRepository countryRepository;
@Autowired
public CountryEndpoint(CountryRepository countryRepository) {
this.countryRepository = countryRepository;
}
package hello;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
[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")]
@marco-mendes
marco-mendes / index.html
Created March 19, 2016 01:37
index.html
<!doctype html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#user-submit').click(function () {
var payload = {
name: $('#user-name').val()
};
@marco-mendes
marco-mendes / package.json
Created March 19, 2016 01:34
package.json
{
"name": "AloMundoNodeMysql"
, "description": "Demonstração de como usar o Express e MySQL juntos"
, "author": "Modificado por *Seu nome*"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "~2.5",
"mysql": "~2.0"
}
@marco-mendes
marco-mendes / AloMundoNodeMySQL.js
Last active March 19, 2016 01:32
AloMundoNodeMySQL.js
// Aplicacao minima Node.JS com MySQL
// Carrega modulos express em mysql
var express = require('express'),
mysql = require('mysql');
// Inicializa conexao com o banco de dados e servidor Web express
var connection = mysql.createConnection({
host : 'localhost',
// Carga de modulos em Javascript. Aqui estou carregando o modulo HTTP, que dar
//suporte a requisicoes em protocolo HTTP
var http = require('http');
// Nesta linha eu crio um servidor Web, que irá ouvir requisições no porto 8080.
// Toda conexao a esse servidor será tratado por uma função criada pelo desenvolvedor.
// Esta funcao gera um cabeçalho HTTP 200 (OK) e então ecoa uma mensagem para
//o navegador que originou a requisição.
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});