GithubHelp home page GithubHelp logo

yusfuu / lightweight-php-framework-for-web-and-apis Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 4.0 90 KB

Simple PHP framework that helps you quickly understand and write simple APIs.

Home Page: https://yusfuu.github.io/Lightweight-PHP-Framework-For-Web-and-APIs/

License: MIT License

PHP 87.35% Shell 0.36% CSS 1.12% Hack 11.05% JavaScript 0.13%
php php-framework framework rest-api api http-router web mvc

lightweight-php-framework-for-web-and-apis's Introduction

Lightweight PHP Framework For Web and APIs

PHP framework that helps you write quickly simple but powerful web apps and APIs

Installation

Use the package manager composer to install required files

Install dependencies

composer install

Hello World

file routes/api.php

<?php

use App\Http\Request;
use App\Routing\Route;

/*
|------------------------------------------------------------------
| API Routes
|------------------------------------------------------------------
|
| Here is where you can register API routes for your application. 
|
*/

Route::get('/hello/{name}', function (Request $request) {
  $name = $request->params->name;
  echo ("Hello, $name");
});

file routes/web.php

<?php

use App\Http\Request;
use App\Routing\Route;
use function App\lib\view;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application.
|
*/

Route::get('/', function (Request $request) {
  return view('welcome', ['lang' => 'PHP']);
});

Available Router Methods

The router allows you to register routes that respond to any HTTP verb:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::delete($uri, $callback);

PHP built-in server

Run the following command in terminal to start localhost web server, assuming ./public/ is public-accessible directory with index.php file:

cd public/
php -S localhost:8000
Going to http://localhost:8000/api/hello/world will now display "Hello, world".
Going to http://localhost:8000/ will render the welcome page.

Example Controller

<?php

namespace App\Controllers;

use App\Http\Request;

class ExampleController extends Controller
{

  /**
   * Display a listing of the resource.
   *
   * @return \Http\Request
   */
  public static function index(Request $request)
  {
    //
  }

  /**
   * Store a newly created resource in storage.
   *
   * @param  \Http\Request  $request
   */
  public static function store(Request $request)
  {
    //
  }

  /**
   * Display the specified resource.
   *
   * @param  \Http\Request  $request
   */
  public static function show(Request $request)
  {
    //
  }

  /**
   * Update the specified resource in storage.
   *
   * @param  \Http\Request  $request
   */
  public static function update(Request $request)
  {
    //
  }

  /**
   * Remove the specified resource from storage.
   *
   * @param  \Http\Request  $request
   */
  public static function destroy(Request $request)
  {
    //
  }
}

Example Model

<?php

namespace App\Models;

class ExampleModel extends Model
{
  /**
   * @var array
   */
  protected $fillable = [];
}

Documentation

Documentation

Contributing

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

License

MIT

lightweight-php-framework-for-web-and-apis's People

Contributors

yusfuu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lightweight-php-framework-for-web-and-apis's Issues

add crud controller boilerplate

it would be such a great feature if the framework had implemented crud on the boilerplate, something similar to mongodb driver.
expect a PR soon ๐Ÿ‘

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.