1. Products

PHP REST API With JWT Authentication

PHP is the simplest language any one can start coding with. PHP brings the best of frontend and backend both the world and it’s easy to integrate with your existing html block. When you start your career with web development using HTML/CSS and the first backend code you integrate is contact form to send email, there you first start working with PHP. That gives PHP a language which every developer in their life has come at least once. 

To extend the uses, PHP brings a lot of predefined functionality like 

  • Print some variable into html document
<body>
<?php 
$firstName= "Nishant";
$lastName="verma";
echo $firstName . ' ' . $lastName; 
?>
</body>
  • Define function in php
<?php 
function add($a,$b){
return $a+$b; 
}
?>
  • Connecting to a database
<?php
class Database{
 
    // specify your own database credentials
    private $host = "localhost";
    private $db_name = "dbName";
    private $username = "username";
    private $password = "password";
    private $port = "3306";
    public $conn;
 
    // get the database connection
    public function getConnection(){
 
        $this->conn = null;
 
        try{
		if($this->port){
            $this->conn = new PDO("mysql:host=" . $this->host . ";port=" . $this->port . ";dbname=" . $this->db_name, $this->username, $this->password);
            }
else{
		$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
}
			$this->conn->exec("set names utf8");
        }
catch(PDOException $exception){
            echo "Connection error: " . $exception->getMessage();
        }
         return $this->conn;
    }
}
?>
  • Execute query into your MySQL database
<?php 
function readAll(){
$query = "SELECT t.* FROM table t";
$stmt = $this->conn->prepare($query);
// execute query
$stmt->execute();
return $stmt;
}
?>
  • Exception handling
<?php
try {
    echo inverse(5) . "\n";
    echo inverse(0) . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
?>

This excited me to create a very simple PHP REST API Generator tool which takes your database as input and writes a full production ready REST API code for you. 
REST API Generator performs an in-depth analysis of your mysql database: all types of relationships between tables, primary and foreign keys, field types and values, validation, etc. This intelligent analysis is used to pre-configure the options adapted to each endpoint of the generated REST API.

  • Primary keys detection and interpretation
  • Secondary keys detection and interpretation
  • Detection of all types of relationships
  • Smart integration of internal/external relationships in CRUD
  • Smart field type detection and integration
  • Detection and integration of validation types
PHP REST API Generator

Download

Comments to: PHP REST API With JWT Authentication

Your email address will not be published. Required fields are marked *

Nishant Kumar Verma

Full Stack Developer, Experience in enterprise application development. Providing solution for scalable SaaS application and developing product to automate part of development efforts.

#CleanCodeArchitect #.Net #C# #NodeJS #TypeScript #React #JavaScript #DesignPattern #SOLID #WebAPI #HTML5 #Bootstrap #CSS

#AWS #Docker #Kubernetes #GIT #GitHubAction #ECS #LoadBalancer #S3 #Lambda #Azure #CI/CD Pipeline

#MongoDB #MSSQL #MySQL #JSON