This file contains hidden or 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
<img src="{{url}}" class="img-responsive img-thumbnail" alt="{{title}}"> | |
</img> |
This file contains hidden or 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
var express = require('express'); | |
var app = express(); | |
var port = 8080; | |
app.use(function(req, res, next) { | |
res.setHeader( | |
'Access-Control-Allow-Origin', '*'); | |
res.setHeader( | |
'Access-Control-Allow-Methods', 'GET, POST'); | |
res.setHeader( |
This file contains hidden or 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
{ | |
"name": "appname", | |
"version": "0.0.1", | |
"dependencies": { | |
} | |
} |
This file contains hidden or 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
var http = require('http'); | |
var server = http.createServer(function (request, response) { | |
var message; | |
var status; | |
if ( request.url === '/hello' ) { | |
message = 'Hello!'; | |
status = 200; | |
} else if ( request.url === '/ola' ) { | |
message = 'Ola!'; |
This file contains hidden or 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
var express = require('express'); | |
var app = express(); | |
app.get('/ola/:nome/:sobrenome', function(request, response){ | |
var nome = request.params.nome; | |
var sobrenome = request.params.sobrenome; | |
response.json({message:'Olá, '+nome+' '+sobrenome}); | |
}); | |
app.get('/hello/:nome/:sobrenome', function(request, response){ |
This file contains hidden or 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
var express = require('express'); | |
var app = express(); | |
app.get('/add/:v1/:v2', function(request, response){ | |
var v1 = parseFloat(request.params.v1); | |
var v2 = parseFloat(request.params.v2); | |
response.json({resultado: v1+v2}); | |
}); | |
app.get('/sub/:v1/:v2', function(request, response){ |
This file contains hidden or 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
var express = require('express'); | |
var app = express(); | |
var bodyParser = require('body-parser'); | |
//Aceitar requisições JSON (Content-Type: application/json) | |
app.use(bodyParser.json()); | |
app.post('/usuarios', function(request, response){ | |
console.log(request.body);//JSON recebido | |
response.json({mensagem:'Recebido!'});//Retornando JSON |
This file contains hidden or 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
var express = require('express'); | |
var expressValidator = require('express-validator'); | |
var app = express(); | |
var bodyParser = require('body-parser'); | |
app.use(bodyParser.json()); | |
app.use(expressValidator({ | |
customValidators: { | |
isPhones: function(values) { | |
var ehArray = Array.isArray(values); |
This file contains hidden or 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
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var TelefoneSchema = new Schema({ | |
_id:false, | |
ddd: Number, | |
numero: Number | |
}); | |
var ContatoSchema = new Schema({ |
This file contains hidden or 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
app.post('/usuarios', function(req, res){ | |
new model.Usuario({nome:'Qualquer'}}).save(function(error, data){ | |
if(error){ | |
res.status(400).json({message:error.message}); | |
} else { | |
res.status(201).json(data); | |
} | |
}); | |
}); |