exssah/exss

This is a library for creating an asynchronous HTTP server using PHP.

0.1.0 2023-10-09 04:45 UTC

This package is not auto-updated.

Last update: 2024-04-23 06:20:10 UTC


README

Exss is a library for creating an asynchronous HTTP server using PHP. It is built on top of the ReactPHP framework. With this library, you can create your asynchronous web app using PHP, and it is similar to Express.js.

Installation

Use the package manager Composer to install Exss.

composer require exssah/exss

Usage

Basic http server

require __DIR__ . '/vendor/autoload.php';

use Exssah\Exss\Exss;
use Exssah\Exss\Req;
use Exssah\Exss\Res;

# create a object of Exss class
$app = new Exss();

# use route methods to accept asynchronous HTTP requests
$app::get('/hello', function(Req $req, Res $res){
  return $res::send('Hello world');
});

# start the server at port 8080
$app::listen(8080, function(){
    echo 'http://localhost:8080';
});

Accept The Request Parameters
ex:- http://localhost:8080/user?id=5&name=Somnath Gupta

require __DIR__ . '/vendor/autoload.php';

use Exssah\Exss\Exss;
use Exssah\Exss\Req;
use Exssah\Exss\Res;

# create a object of Exss class
$app = new Exss();

# use route methods to accept asynchronous HTTP requests
#ex:- http://localhost:8080/user?id=5&name=Somnath Gupta

$app::get('/user', function(Req $req, Res $res){

  $userID = $req::params('id'); #'null' if not exist
  $userName = $req::params('name'); #'null' if not exist

 #use the sendJson method to send a JSON response
  return $res::sendJson([
    'id' => $userID,
    'name' => $userName,
  ]);

});

# start the server at port 8080
$app::listen(8080, function(){
    echo 'http://localhost:8080';
});

Accept The Request Body

URl:- http://localhost:8080/user

Body
{
"username" : "Somnath Gupta",
"gmail" : "testgmail@gmail.com",
"password" : "U7%)#",
}

require __DIR__ . '/vendor/autoload.php';

use Exssah\Exss\Exss;
use Exssah\Exss\Req;
use Exssah\Exss\Res;

# create a object of Exss class
$app = new Exss();

# use route methods to accept asynchronous HTTP requests

$app::post('/user', function(Req $req, Res $res){

  $username = $req::body('username'); #'null' if not exist
  $gmail = $req::body('gmail'); #'null' if not exist
  $password = $req::body('password'); #'null' if not exist

 #use the sendJson method to send a JSON response
  return $res::sendJson([
    'username' => $username,
    'gmail' => $gmail,
    'password' => $password,
  ]);

});

# start the server at port 8080
$app::listen(8080, function(){
    echo 'http://localhost:8080';
});

Your can use other fetchers of ReactPHP framework

1) Promise , 2) Async Utilities, 3) Browser Api's

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Step 1: Download, install, and configure PHP and Composer to your local computer.

Step 2: Now Fork a repo

Step 3: Download the code to your local machine

Step 4: Open the folder 'Exss'

Step 5: Open Terminal

Step 6: Run this command to download all the necessary dependencies.

composer install

Step 7: If you don't know about ReactPHP framework then you can visit there