sml/sml-frame

A Tiny framework for handling api's the easy way

v0.0.5 2017-05-13 21:59 UTC

This package is not auto-updated.

Last update: 2024-04-14 00:07:19 UTC


README

Getting started

run composer install edit the .htaccess file to match your file structure

Basic setup

require_once 'vendor/autoload.php';

$app = new Sml\Sml();

# Run the application
$app->run();

ROUTING with request

require_once 'vendor/autoload.php';

$app = new Sml\Sml();

$app::get('/', function(){
  echo 'test';
});

# If you want to pass arguments to the function you do this with regEx values
# Supported values are for Strings and Ints

# String and int value

$app::get('/user/(\w+)/(\d+)', function( $string, $int ){

  # You can then use the params here

});


# POST

$app::post('/user', function() use( $app ) {

  # To get the post request you can do:

  # This recives a json encoded body for you, and returns as obj.
  # If you want a array you can pass true into the json( true )
  $app->request()->json();

  # This recives the x-www-form-urlencoded body ( normal POST )
  $app->request()->body();

});

# Run the application
$app->run();

Response

To use the response obj you need yo inject $app onto your functions

require_once 'vendor/autoload.php';

$app = new Sml\Sml();

$app::get('/', function() use( $app ){
  $app->response( 200, "it Works" )->send();
});

# You can also send back json_response by chaining the sendJson method onto the response method.
$app::get('/', function() use( $app ){
  $app->response( 200, "it Works" )->sendJson();
});

$app->run();

Changelog

version 0.0.2

  • Added support for POST, GET, PUT, DELETE routes
  • Added exception class for handling errors
  • Added Response obj
  • Added Request obj
  • Added the use of env file

version 0.0.1

  • Included simple get Route support.