Code Monkey home page Code Monkey logo

router's Introduction

Router

Classe php para trabalhar REST API

Carregador de template

	Router::view("home.html");

Alteração do conteúdo do template com base nas flags (Template View)

	Router::view("home.html", ["#{titulo}#" => "Bem vindo ao site"] );

JWT | Cria Jwt

	Router::Jwt();

JWT | Valida o Jwt

Enviar o jwt no Authorization, header da requisição.

Se o jwt for inválido irá cortar o fluxo da aplicação e gerar um erro

	Router::validateJwt();

HTTP GET

	Router::get('/', function(){
		Router::view("home.html", ["#{titulo}#" => "Bem vindo ao site"] );
	});

HTTP GET Com parâmetros dinâmicos no endpoint | {parametro}

	Router::get('/idUsuario/{cpf}', function($params){
		echo $params->cpf;
	});

HTTP POST | x-www-form-urlencoded

	Router::post('/dados', function(){
		print_r($_POST);
	});

Recuperando Json no corpo da requisição

	Router::getJson();
	Obrigatório Stringify
	### Ex:
	
	Router::post('/recebejson', function(){
		$dados = Router::getJson();
		echo $dados->nome;
	});

HTTP POST | JSON

	Router::post('/dados', function(){
		var_dump( Router::getJson() );
	});

HTTP PUT | JSON

	Router::put('/dados', function(){
		var_dump( Router::getJson() );
	});

HTTP DELETE

	Router::delete('/dados/{cod}', function($params){
		echo $params->cod;
	});

Router::json | Resposta em json

	Router::get('/dados', function(){
		Router::json( array("usuario" => "soriano") );
	});

Configuração Dev | error_reporting, display_errors

	Router::dev();

Página não encontrada | Deixar na última linha do arquivo

	Router::notFound("notFound.html");

router's People

Contributors

gustavosoriano avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.