Public
Snippet $1 authored by Gabriel Pinto Machado

Base node

Edited
const express = require('express')
const server = express()
var bodyParser = require('body-parser')

server.use(bodyParser.urlencoded({ extended: false }))
server.use(bodyParser.json())

const mock = [
	{
		tipo: 'Mãe',
		nome: 'Beltrana de tal',
		sexo: 'F',
		familiares: 
			[
				{
					tipo: 'Mãe',
					nome: 'Beltrana de tal'
				},
			],
		nacionalidade: 'Brasileira',
		naturalidade: 
			{
				cidade: 'Porto Alegre',
				UF: 'RS'
			},
		abrigo: 
			{
				id: 12345678765432,
				nome: 'Lar Mãe Celia'
			}
	}, 
]

server.get('/', function(req, res, next) {
	res.send('Its working')
	res.end()
})

server.get('/abrigos', function(req, res, next) {
	res.setHeader('Content-type', 'application/json')
	res.send(mock)
})

server.post('/abrigos', function(req, res, next) {
	mock.push(req.body)
	res.send(200, 'Funcionou!')
	res.end()
})

server.listen(8888, function() {
	console.log('server listening on port 8888')
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!