Skip to content

jagroop/rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST

php version

REST is usefull scaffold for making rest APIs using php. It is simple, fast and lightweight.

Table of contents

Installation

$ git clone https://github.com/jagroop/rest.git
$ cd rest
$ composer install

Url Structure

http://localhost/rest/web/class/method/param_1/param_2/..../param_n

Naming conventions

  • All files in app folder should be in "title case", for example: App.php, Users.php, UserPosts.php etc.

Database

PDO Query Builder

Cache

Simple PHP Cache

Helpers

Laravel 5 Helpers for Non-Laravel Projects

New helpers

Validations

GUMP Validator

New Validation Rules:

//unique,table_name or if column name is different in db unique,table_name:col_name
$rules = array('email' => 'required|valid_email|unique,users');

//exist,table_name or exist,table_name:col_name
$rules = array('user_id' => 'required|exist,users:id');

$request = request(['name', 'email']);

$this->validate($request, $rules);

//Now you can insert your data in DB

$this->db->table('users')->insert($request);

Sending Mails

use App\Artisan\Mail;

$user = $this->db->table('users')->where('id',1)->get();

//templates are in resources/email folder

$mail = Mail::send('template_name', compact('user'))
			->to('example@gmail.com', 'John Doe')
			->subject('This is a test subject')
			->deliver();

Sending Push Notifications

use App\Artisan\Notification;

$user = $this->db->table('users')->where('id',1)->get();

$payload = [
	'message' => 'Test notification.',
	'badge' => 2
];

Notification::send($user, $payload);

Asynchronous HTTP requests (Non-Blocking)

async('sendNewOfferEmail', ['offer_id' => 123]);

//Async requests target functions are defined in app/Async.php

//example:

class Async {

	public function sendNewOfferEmail(){
		$offerId = (int) request('offer_id');
		//...
	}
}

forthebadge